Getting help In [1]: from os.path import basename In [2]: basename? Type: function String Form: File: c:\users\user\v\ipython-pywaw\lib\ntpath.py Definition: basename(p) Docstring: Returns the final component of a pathname
History In [6]: import math In [7]: spam = math.sqrt(27) In [8]: print spam 5.19615242271 In [9]: %history 6-8 import math spam = math.sqrt(27) print spam In [10]: %save test.py 6-8 The following commands were written to file `test.py`: import math spam = math.sqrt(27) print spam
Session logging In [1]: %logst %logstart %logstate %logstop In [1]: %logstart Activating auto-logging. Current session state plus future input saved. Filename : ipython_log.py Mode : rotate Output logging : False Raw input log : False Timestamping : False State : active In [2]: x = 5 In [3]: Do you really want to exit ([y]/n)? y
More than a list In [6]: files = !ls In [7]: files Out[7]: ['1.txt', '2.txt', 'hello.txt'] In [8]: files.s Out[8]: '1.txt 2.txt hello.txt' In [9]: files.n Out[9]: '1.txt\n2.txt\nhello.txt' In [10]: files.p Out[10]: [path(u'1.txt'), path(u'2.txt'), path(u'hello.txt')] In [11]: files.grep(r'^\d') Out[11]: ['1.txt', '2.txt']
Removing unversioned files In [11]: !hg st A hello.txt ? 1.txt ? 2.txt In [12]: lines = !hg st In [13]: files = lines.grep(r'^\?').fields(1) In [14]: files Out[14]: ['1.txt', '2.txt'] In [15]: !rm $files.s In [16]: !ls hello.txt
%timeit In [13]: def factorial(n): ....: if n in [0, 1]: ....: return 1 ....: else: ....: return n * factorial(n - 1) ....: In [14]: %timeit factorial(120) 10000 loops, best of 3: 32.5 us per loop In [28]: def factorial2(n): ....: return reduce(operator.mul, xrange(1, n + 1)) ....: In [29]: %timeit factorial2(120) 100000 loops, best of 3: 15.9 us per loop
Hire me! • > 2 years in Python • mostly web apps (Django, Flask) • some desktop experience (Qt) • powered by curiosity (and caffeine) • [email protected] • http://www.goldenline.pl/zbigniew-siciarz