In [2]: print "hello world" hello world
In [3]: %hi %hist %history
In [3]: %hist 1: True == False
2: print "hello world"
In [4]: In Out[4]: ['\n', 'True == False\n', 'print "hello world"\n', 'ipmagic("%hist ")\n', 'In\n']
In [5]: Out Out[5]: {1: False, 4: ['\n', 'True == False\n', 'print "hello world"\n', 'ipmagic("%hist ")\n', 'In\n', 'Out\n'], 5: }
In [6]: print i, _ii, _iii, , __, Out In ipmagic("%hist ") {1: False, 4: ['\n', 'True == False\n', 'print "hello world"\n', 'ipmagic("%hist ")\n', 'In\n', 'Out\n', 'print i, ii, _iii, , , \n'], 5: {...}} ['\n', 'True == False\n', 'print "hello world"\n', 'ipmagic("%hist ")\n', 'In\n', 'Out\n', 'print i, ii, _iii, , , ___\n'] False
编辑
- 支持行编辑,默认为vi键绑定。可以按 ESC 允许行被编辑
- 允许方便编辑所以代码
- %edit调出 环境变量EDITOR定义的编辑器
- %edit star stop 可以对某一区域编辑
In [4]: hist 1: class A: def init(self, start, end): """Some comment here."""2: a = 1 3: b = 2 4: c = 0
%edit Will open up an empty editor %edit 2 4 Will open an editor containing lines 2 and 4 %edit 1 Will open up the class definition %edit 1:4 w Will open up the editor with lines 1, 2 and 3
会话和日志 每次使用后会话都有记录。并且可以重放会话快速恢复到上次会话的最后状态
开始记录日志可以使用 -log 或 -logfile 在命令行或者使用%logstart在interpreter。%logstate可以显示当前log的状态
%logoff可以暂停记录,%logon恢复
继续某次会话可以通过命令行使用 -logfile
对象自省 自省可以像标准python那样 ?是个快捷键 例子
In [2]: sys.path? Type: list Base Class:
String Form: ['', '/usr/bin', '/disk2/ag/common', '/usr/lib/python24.zip', '/usr/lib/python2.4', '/usr/lib/pyt <...> 2.4/site-packages/Numeric', '/usr/lib/python2.4/site-packages/gtk-2.0', '/home/dstanek/.ipython'] Namespace: Interactive Length: 13 Docstring: list() -> new list list(sequence) -> new list initialized from sequence's items
In [1]: class C(object): ...: a = "a string" ...: def f(self, name, value): ...: """my docstring here""" ...:其他技巧In [2]: C.a? Type: str Base Class:
String Form: a string Namespace: Interactive Length: 8 Docstring: str(object) -> stringReturn a nice string representation of the object. If the argument is a string, the return value is the same object.In [3]: ?C.f Type: instancemethod Base Class:
String Form:
Namespace: Interactive File: /mnt/home/dstanek/ Definition: C.f(self, name, value) Docstring: my docstring here
- 集成调试器
- 集成profiler
- Python jobs can be run in the background in a thread.
- 支持配置文件
It's a good thing and is available at http://ipython.scipy.org/
A sprint to add other cool things may be a useful exercise.
To set ipython to be the default:
Python honors the environment variable PYTHONSTARTUP and will execute at startup the file referenced by this variable. If you put at the end of this file the following two lines of code:
import IPython IPython.Shell.IPShell().mainloop(sys_exit=1)
评论