Ref : http://object22.blogspot.com/2011/12/ipython-cheat-sheet.html
Part I – basic commands
var – tab completion of a variable that starts with prefix ‘var’
who [int, str, ..]- list available variables, or just those with the give type
whos – a table of all the variables, their type and values
psearch var* [type] – search for variables using the pattern and possibly type
reset – clear all variables
logstate – has the logging been started or not
logstart – start logging into (ipython_log.py by default)
logon – turn logging on
logoff – turn logging off
lsmagic – list all built in commands, called magic commands. These are prefixed with % to differentiate between variables if they have the same name.
magic – scrolling help about the magic commands.
cmd? – overview of the command, e.g lsmagic?
cmd?? – more information about the command including source code
var? – information about the variable
page obj – pretty print the object
func arg1, arg2 – automatically adds parentheses and calls func(arg1, arg2)
/func – same as func()
, func arg1, arg2 – same as func(“arg1”, “arg2”)
help(keyword) – manual pages on keyword (module, function, etc)
help() -> topics – lists all the help topics
pdef func – shows the function signature (list of arguments it takes)
pdoc func – prints doc string for the function
pinfo func – same as func?
psource func – shows the source code for the function
pfile func – opens the source file with the func
edit -x func – opens the source with default editor on the line with the function
Welcome to Python Cheatsheet! ☕️ Anyone can forget how to make character classes for a regex, slice a list or do a for loop. This cheat sheet tries to provide a basic reference for beginner and advanced developers, lower the entry barrier for newcomers and help veterans refresh the old tricks. IPython - An enhanced Interactive Python - Quick Reference Card 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 ipython notebook -pylab qt Open IPython Notebook with popup graphs.
Part II – navigation and the shell
Analogous to standard shell commands there are pwd, cd, pushd, popd, dirs Tab completion also works with these.
bookmark name [path] – bookmarks the current directory or the given path
bookmark -l – lists all saved bookmarks
bookmark -d name – removes bookmark name
dhist – prints the directory navigation history. cd can take numbers from that list as argument, e.g cd -2
!cmd – runs cmd as a shell command, e.g !ls
alias – lists defined aliases for shell commands we can use
alias newname cmd args – creates a new alias with newname as name for the cmd with args
unalias name – removes alias name
var = !cmd – store the output of cmd into variable
pycat name – prints the highlighted contents of the file
run script.py – runs a python file called script.py and prints the output. Also the functions, variables and modules from the script REMAIN in our namespace!
run -p script.py – run the profiling on the script
Part III – input manipulation
ctrl+p, ctrl+n, arrow keys – previous next command from history
_i, _ii, _iii – prints 1,2 or 3 previous command
_i[X] – prints command number X, e.g _i1
In[X] – prints X-th input commands
hist [N1-N2] – prints a list of previously typed commands, or N1 through N2 previous commands
macro name cmdA-cmdB cmdX – defines a mactor that can execute commands from the history
print macro – prints a macro
edit file – opens up the default editor to edit a file
edit [N1-N2] – edit the history N1 through N2
save file N1-N2 – saves the historey N1 through N2 into file.py
cpaste – paste in source code without, IPython will not format it.
Out[X] – prints the X-th output if it exists
func; – putting does not echo the return of the function and does not put it into Out dictionary
Note! The following commands do not work in IPython 0.11:
store var – save the variable in profile for future use
p var – shorthand for print
exec cmd – execute a command
runlog – executes the IPython log
IPython / Jupyter¶
- Using IPython makes interactive work easy.
- Better shell
- Notebook interface
- Embeddable kernel
- Parallel python
IPython shell shortcuts¶
- TAB expansion to complete python names and file paths
- ~ and * directory / file expansion
- many 'magic' methods:
Help¶
%pdoc
%pdef
%psource
for docstring, function definition, source code only.
Run¶
To run a program directly from the IPython console:
Ipython Magic Commands Cheat Sheet
%run
has special flags for timing the execution of your scripts (-t
) or for running them under the control of either Python's pdb debugger (-d
) or profiler (-p
):
Other Commands¶
%reset
is not a kernel restart- Restart with
Ctrl+.
in 'qtconsole' import module ; reload(module)
to reload a module from disk
Debugging¶
OS Commands¶
History¶
Ipython Cheat Sheet Template
GUI integration¶
Start with ipython --gui=qt
or at the IPython prompt:
Arguments can be wx
, qt
, gtk
and tk
.
Matplotlib / pylab graphics in an iPython shell¶
Start with: ipython --matplotlib
( or --matplotlib=qt
etc...)
At the IPython prompt:
%pylab
makes the following imports:
At the command prompt:
alternative: --matplotlib inlineor within IPython:
To embed plots, SVG or HTML in qtconsole, call display:
IPython Notebook web-based interface¶
- Start with: ipython notebook and switch to browser
- Keyboard shortcuts:
Enter
to edit a cellShift + Enter
to evaluateCtrl + m
orEsc
for the 'command mode'
In command mode:
Ipython Notebook Cheat Sheet
Papermill is a tool for parameterizing and executing Jupyter Notebooks.
Comments are closed.