diff --git a/README.md b/README.md index 765bb90..b6864a7 100644 --- a/README.md +++ b/README.md @@ -306,8 +306,17 @@ class : ### Enum ```python import enum -class (enum.Enum): - = # or enum.auto() +class (enum.Enum): + = # or enum.auto() + +. == +(value) == +.name == +.value == + +Cutlery = Enum('Cutlery', ['knife', 'fork', 'spoon']) +list() == [, , ...] +random.choice(list()) == random ``` ### Copy @@ -382,8 +391,6 @@ with open(, 'w', enconding='utf-8') as file: file.write(json.dumps()) ``` - - SQLite ------ ```python @@ -405,7 +412,6 @@ db.execute() db.commit() ``` - Exceptions ---------- ``` @@ -644,7 +650,6 @@ Flatten List Libraries ========= - Plot ---- ``` @@ -654,7 +659,6 @@ matplotlib.pyplot.show() matplotlib.pyplot.savefig() ``` - Web --- ``` @@ -699,12 +703,44 @@ timeit.timeit('"-".join(str(n) for n in range(100))', number=10000) ``` import pycallgraph graph = pycallgraph.output.GraphvizOutput() -graph.output_file = +graph.output_file = "{}-{}.png".format("profile", + get_current_datetime_string()) with pycallgraph.PyCallGraph(output=graph): + +def get_current_datetime_string(): + now = datetime.datetime.now() + return get_datetime_string(now) + +def get_datetime_string(a_datetime): + return a_datetime.strftime('%Y%m%d%H%M%S') ``` +Audio +----- +Saves list of floats of size 0 to 1 to a wav file. +``` +import wave +import struct +frames = [struct.pack("%dh"%(1), int((a-0.5)*60000)) for a in ] +wf = wave.open(, 'wb') +wf.setnchannels(1) +wf.setsampwidth(4) +wf.setframerate(44100) +wf.writeframes(b''.join(frames)) +wf.close() +``` +Coockboock +========== + +Dictionary +---------- + +Filter by keys: +``` +{k: v for k, v in d.iteritems() if k in [2,3]} +```