From f2fe888c76ba92d64b3a8168af937ea0dce76c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 14 Apr 2018 04:28:36 +0200 Subject: [PATCH] Isinstance, basic profile --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 84ac316..91bb5dc 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ List .extend() .sort() .reverse() + = sorted() + = reversed() ``` ```python @@ -146,7 +148,7 @@ type() # / / ... ``` ```python import numbers -isinstance(, numbers.Number) # numbers.Integral, numbers.Real +isinstance(, numbers.Number) # Integral, Real, Rational, Complex ``` @@ -780,13 +782,20 @@ Curses ------ ```python 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 + +def get_border(screen): + Coords = collections.namedtuple('Coords', ['x', 'y']) + height, width = screen.getmaxyx() + return Coords(width - 1, height - 1) ``` #### Gets char from int: @@ -796,11 +805,20 @@ chr() Profile ------- +#### Basic +```python +from time import time +start_time = time() +... +duration = (time() - start_time) +``` + #### Times execution of the passed code: ```python import timeit timeit.timeit('"-".join(str(n) for n in range(100))', number=10000) ``` + #### Generates a PNG image of call graph and highlights the bottlenecks: ```python import pycallgraph @@ -809,6 +827,7 @@ graph.output_file = get_filename() with pycallgraph.PyCallGraph(output=graph): ``` + #### Utility code for unique PNG filenames: ```python def get_filename():