Show Menu
Cheatography

IPython Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Command Line Options

ipython
Open IPython terminal console
ipython qtconsole
Open IPython qtconsole
ipython notebook
Open IPython Notebook (browser interface)
ipython notebook --pylab inline
Open IPython Notebook with inline graphs

Inspection

obj?, obj??
Get help, or more help for object
?obj, ??obj
Same as above
?foo.abc
List names in 'foo' containing 'abc' in them.
%magic
Inform­ation about magic functions
%quickref
Print quick guide to relevant IPython (console, notebook, qtconsole)

Shortcuts

Tab
Code and path comple­tion. Second TAB allows cycling through options.
Ctrl + Enter [qtcon­sole]
Allows entering multiple statements (Cell mode)
Shift + Enter
Executes current cell
Ctrl + R [shell]
Reverser history search (All readline shortcuts are supported)
 

Notebook Magics

%%java­script
Run code below as javascript
%%html
Display markup below as html

Executing Code

%time or %%time
Run and output time statement or block (first line for block is setup)
%prun %%prun
Profile statement or block
%run
Run a file and import resulting variables into namespace
%%script <ex­ecu­tab­le>
Run code below using <ex­ecu­tab­le>. --bg runs code in backgrounf and returns Popen object
%%ruby, %%perl, %%bash
Shortcuts for %%script <ru­by|­per­l|b­ash>
!<c­md>
Run shell command and return output
%sh <cm­d>, !!<cmd
Run command and capture output as a list of lines
%%capture
Run code in cell and capture stderr and stdout
 

File System Magics

cd, ls, mkdir
Aliases for python commands with the same functi­onality
%bookmark
Name current folder. Note that cd <bo­okm­ark> will work.
%dhist, _dh
Display directory history
%pushd, %popd
Save| Restore current directory
%pycat
Display python source with syntax highli­ghting
%%writ­efile
Write the text below to a file

Console and Output Magics

%logstart, %logstop
Start|Stop saving commmands into a file (by default IPytho­n.py)
%less
Run command output through pager
%pprint
Toggle automatic pretty printing
%history
Output command history
%recall <nu­m>
Re executed command #num from history
%tb
Print latest Traceback
%alias
Name statements for later use.
_
Get result of last statement. Use _i, _ii,_iii to get back in history. Use _<n­um> for going back to a result of a specific line in history.