IPython Console Cheatsheet

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

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


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s