obj?, obj?? : Get help, or more help for object (also works as ?obj, ??obj). ?foo.*abc* : List names in 'foo' containing 'abc' in them. %magic : Information about IPython's 'magic' % functions.
Magic functions are prefixed by % or %%, and typically take their arguments without parentheses, quotes or even commas for convenience. Line magics take a single % and cell magics are prefixed with two %%.
The following magic functions are currently available:
%alias: Define an alias for a system command. %alias_magic: :: %autoawait:
%autocall: Make functions callable without having to type parentheses. %autoindent: Toggle autoindent on/off (deprecated) %automagic: Make magic functions callable without having to type the initial %. %bookmark: Manage IPython's bookmark system. %cd: Change the current working directory. %cls: Clear screen. --- more ---
In [2]: %time? Docstring: Time execution of a Python statement or expression.
The CPU and wall clock times are printed, and the value of the expression (if any) is returned. Note that under Win32, system time is always reported as 0, since it can not be measured.
This function can be used both as a line and cell magic:
- In line mode you can time a single-line statement (though multiple ones can be chained with using semicolons).
- In cell mode, you can time the cell body (a directly following statement raises an error).
This function provides very basic timing functionality. Use the timeit magic for more control over the measurement.
.. versionchanged:: 7.3 User variables are no longer expanded, the magic line is always left unmodified.
常用指令
下面是一些常用的魔术命令的例子:
%run:运行外部Python脚本,比如 %run hello.py。
%load:载入外部脚本的内容到一个代码单元格中,比如 %load hello.py。
%time:测量单行代码的执行时间,比如 %time x = sum(range(100))。
%timeit:测量单行代码的平均执行时间,比如 %timeit x = sum(range(100))。