IPython Interactive Python shell
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
obj?obj.<TAB>%run <script.py>
%timeit <expr>
!<command>
%debug%history%load_ext autoreload
Concepts
- In[n] your input
- Out[n] result
- _ __ ___ last 3 outputs
Help and inspection
<obj>?<obj>??<obj>.<TAB>
*<pattern>*?
%psource <obj>
%pdoc <obj>
%pfile <obj>
%quickref%magic%lsmagic%<magic>?Running code
%run <script.py> <args>
%run -i <script.py>
%run -t <script.py>
%run -p <script.py>
%run -d <script.py>
%run -m <module>
%load <file>
%edit%paste%cpaste%%writefile <file>
%save <file> <range>
%reset%reset -fTiming
%time <stmt>
%timeit <stmt>
%timeit -n <N> -r <R> <stmt>
%%time%%timeit%prun <stmt>
History and output
%history%history -n%history -g <text>
%history -l <N>
%rerun%rerun -g <text>
In[<n>]Out[<n>]_ / __ / ___%macro <name> <n1-n2>
%store <var>
Shell and system
!<command>
<var> = !<command>
!<command> {<pyvar>}
%%bash%cd <dir>%pwd%ls%env <VAR>=<value>
%alias <name> <cmd>
%pushd <dir> / %popd
%pip install <pkg>
%conda install <pkg>
Debugging
%debug%pdb on%pdb off%xmode Verbose%tb%debug --breakpoint <file:line>
Modules and workspace
%load_ext autoreload
%autoreload 2%autoreload 1%autoreload 0%aimport <module>
%who%whos%who_ls%matplotlib inline
%matplotlib -lConfig and shortcuts
ipython profile create
ipython --profile=<name>
ipython -i <script.py>
ipython -c "<code>"
ipython locate%colors <scheme>
%automagic| Key | Does |
|---|---|
Tab |
Complete or cycle |
Ctrl+R |
Search history |
Ctrl+O |
Open new line |
Esc Enter |
Force run block |
Ctrl+L |
Clear screen |
Ctrl+D |
Exit |
Recipes
%load_ext autoreload%autoreload 2import mymodmymod.run()# edit mymod.py, then call again
%run script.py%debug# or start under pdb from the top:%run -d script.py
%timeit sorted(data)%timeit -n 100 -r 5 list_sort(data)
files = !ls *.csvfor f in files: print(f)%%bashgrep -c error app.log



