Introspection
引用
Using a question mark ( ? ) before or after a variable will display some general information about the object
引用
Using ?? will also show the function’s source code if possible:
引用
? has a final usage, which is for searching the IPython namespace in a manner similar to the standard UNIX or Windows command line. A number of characters combined with the wildcard ( * ) will show all names matching the wildcard expression.
Magic Command
%quickref |
Display the IPython Quick Reference Card |
%magic |
Display detailed documentation for all of the available magic commands |
%debug |
Enter the interactive debugger at the bottom of the last exception traceback |
%hist |
Print command input (and optionally output) history |
%pdb |
Automatically enter debugger after any exception |
%paste |
Execute pre-formatted Python code from clipboard |
%cpaste |
Open a special prompt for manually pasting Python code to be executed |
%reset |
Delete all variables / names defined in interactive namespace |
%page |
OBJECT Pretty print the object and display it through a pager |
%run |
script.py Run a Python script inside IPython |
%prun |
statement Execute statement with cProfile and report the profiler output |
%time |
statement Report the execution time of single statement |
%timeit |
statement Run a statement multiple times to compute an emsemble average execution time. Useful for timing code with very short execution time |
%who, %who_ls, %whos |
Display variables defined in interactive namespace, with varying levels of information / verbosity |
%xdel |
variable Delete a variable and attempt to clear any references to the object in the IPython internals |
Matplotlib Integration and Pylab Mode
引用
ipython --pylab
Searching and Reusing the Command History
<Ctrl-P> <up arrow>
<Ctrl-N> <down arrow>
<Ctrl-R>
Input and Output Variables
引用
IPython stores references to both the input (the text that you type) and output (the object that is returned) in special variables. The previous two outputs are stored in the _ (one underscore) and __ (two underscores) variables, respectively
引用
Input variables are stored in variables named like _iX , where X is the input line number. For each such input variables there is a corresponding output variable _X . So after input line 27, say, there will be two new variables _27 (for the output) and _i27 for the input.
Logging the Input and Output
引用
IPython is capable of logging the entire console session including input and output.Logging is turned on by typing %logstart, %logoff, %logon, %logstate, and %logstop .
Tips
引用
import some_lib
reload(some_lib)