Python and Libraries Cheatsheet =============================== Sum --- ``` sum() ``` Profile ------- ``` import pycallgraph graph = pycallgraph.output.GraphvizOutput() graph.output_file = whith pycallgraph.PyCallGraph(output=graph): ``` SQLite ------ ``` import sqlite3 db = sqlite3.connect() ``` ### Read ``` cursor = db.execute() if cursor: cursor.() db.close() ``` ### Write ``` db.execute() db.commit() ``` Curses ------ ``` import curses def main(): curses.wrapper(draw) def draw(screen): screen.clear() screen.addstr(0, 0, "Press ESC to quit.") while screen.getch() != 27: pass ``` Regex ----- ``` import re re.sub(, , ) re.search(, ) ``` Threading --------- ``` import threading ``` ### Thread ``` thread = threading.Thread(target=, args=(, )) thread.start() thread.join() ``` ### Lock ``` lock = threading.Rlock() lock.acquire() lock.release() ``` Bottle ------ ``` import bottle ``` ### Run ``` bottle.run(host='localhost', port=8080) bottle.run(host='0.0.0.0', port=80, server='cherypy') ``` ### Static request ### Dynamic request ### REST request Type ----