IPython quick reference

Here are some notes I took while watching the ShowMeDo video tutorial series on IPython. I highly recommend these videos — I had been using IPython for several months but after seeing these tutorials I learned a lot.

First is the quick reference to get you started, then is the not-so-quick reference section

Changing directories

pwd display present working directory
ls list the contents of the present working directory
cd directoryname Change to the directory directoryName
cd C:/Python25/work On Windows, use “/” instead of the typical “\” for path separators
cd C:/My/ Documents Either precede spaces in filenames with a “/” to say that it is part of the filename . . .
cd ‘C:/My Documents’ or, enclose the name in quotes

Running programs

run scriptName.py runs scriptName.py, a Python script in the present working directory

 

The workspace

whos lists the objects currently available in the namespace
reset delete all varables currently in the namespace

Getting help

? at the end of a variable, function, or command name shows help for that object
open? shows help for open, a built-in Python function
run? shows help for run an IPython “magic” function

 

Being lazy: TAB completion

Type one or two letters, then hit the TAB key. This is called tab completion

IPython will provide a list of directories, commands, and variables that match the letters you typed. Type a couple more letters of one of the choices in the list, then hit TAB again to further narrow the search.

See what an object can do (”introspection”)

name.[TAB] Where name is an object and [TAB] means hit the Tab key. Shows methods and attributes of the object, name

Introspection example

x = 'asdf'
x. # (after the dot, hit the tab key) 
Output:
x.__add__   x.__class__   x.__contains__  ...   ...   ...   x.upper   x.zfill

After discovering that the string object, x, has something called upper, check the help on it:

x.upper?

Being lazy: up arrow

up arrow cycle through previous commands
down arrow (after hitting up arrow) cycle through next commands

Note: If you enter the first couple characters of a command before hitting the up arrow, you will only be shown commands that start with those characters.

Exiting

Exit exits IPython without confirmation
exit() exits IPython with confirmation
close the window exits IPython without confirmation

 

IPython Not-so-quick Reference

Below are links to other posts on this site about the following topics:

Tags:

Leave a Reply