From 6ddef76b9e4080b68db8641ed800b71e1d069634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Thu, 9 Nov 2017 19:23:41 +0100 Subject: [PATCH] Added basic commands --- README.md | 234 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 234 insertions(+) diff --git a/README.md b/README.md index 1a65b44..2d008bd 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,240 @@ bottle.run(host='0.0.0.0', port=80, server='cherypy') Type ---- +``` +type() is int/str/set/list +``` +``` +import numbers +isinstance(, numbers.Number) +``` + +Arguments +--------- +``` +import sys +sys.argv +``` + +Enumerate +--------- +``` +for i, in enumerate() +``` + + +System Commands +--------------- +### Read File +``` +with open(, encoding='utf-8') as file: + return file.readlines() +``` + +### Write to File +``` +with open(, 'w', enconding='utf-8') as file: + file.write() +``` + +### Execute Command +``` +import os +os.popen().read() +``` + + +JSON +---- +``` +import json +``` + +### Read File +``` +with open(, encoding='utf-8') as file: + return json.load(file) +``` + +### Write to File +``` +with open(, 'w', enconding='utf-8') as file: + file.write(json.dumps()) +``` + + +Datetime +-------- +``` +import datetime +now = datetime.datetime.now() +now.strftime('%Y%m%d') +now.strftime('%Y%m%d%H%M%S') +``` + +String +------ +``` +str.replace(, , ) +.isnumeric() +``` + +Enum +---- +``` +import enum +class (enum.Enum): + = +``` + +Copy +---- +``` +import copy +copy.copy() +copy.deepcopy() +``` + +Infinity +-------- +``` +float("inf") +``` + +Plot +---- +``` +import matplotlib +matplotlib.pyplot.plot(, ...) +matplotlib.pyplot.show() +matplotlib.pyplot.savefig() +``` + +List +---- +``` +[::] +``` + +Lambda +------ +``` +lambda , : +lambda: +``` + +[For] +----- +``` +[i+1 for i in range(10)] +[i+1 for i in range(10) if i > 5] +[i+j for i in range(10) for j in range(10)] +``` + +Class +----- +``` +class : + def __init__(self, ): + self.a = + def __repr__(self): + return str({'a': self.a}) + def __str__(self): + return str(self.a) +``` + +Random +------ +``` +import random +random.random() +random.randint(, ) +random.shuffle() +``` + +Range +----- +``` +range() +range(, ) +range(, , ) # Negative step for backward +``` + +List +---- +``` +.sort() +.reverse() +.extend() +``` + +Print +----- +``` +print(, , end='', sep='', file=) +``` + +Format +------ +``` +'{}'.format() +``` + +``` +{:} -> ' ' +{:>} -> ' ' +{:^} -> ' ' +{:_} -> '____' +{:.} -> '' +{:.} -> ' ' +{:.f} -> ' 3.14' +``` + +Text Wrap +--------- +``` +import textwrap +textwrap.wrap(, ) +``` + +Dictionary +---------- +.items() +.get(, ) +.setdefault(, ) +``` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +