IPython—an interactive shell
Scientists and engineers are used to experimenting. IPython was created by scientists with experimentation in mind. The interactive environment that IPython provides is viewed by many as a direct answer to Matlab, Mathematica, and Maple. You can find more information, including installation instructions, at: http://ipython.org/.
IPython is free, open source, and available for Linux, Unix, Mac OS X, and Windows. The IPython authors only request that you cite IPython in scientific work where IPython was used. Here is the list of basic IPython features:
Tab completion
History mechanism
Inline editing
Ability to call external Python scripts with %run
Access to system commands
Pylab switch
Access to Python debugger and profiler
The Pylab switch imports all the Scipy
, NumPy
, and Matplotlib
packages. Without this switch, we would have to import every package we need, ourselves.
All we need to do is enter the following instruction on the command line:
The quit()
function or Ctrl + D quits the IPython shell. We might want to be able to go back to our experiments. In IPython, it is easy to save a session for later:
Let's say we have the vector addition program that we made in the current directory. We can run the script as follows:
As you probably remember, 1000
specifies the number of elements in a vector. The -d
switch of %run
starts an ipdb
debugger and on typing c
, the script is started. n steps through the code. Typing quit
at the ipdb
prompt exits the debugger.
We can also profile our script by passing the -p
option to %run
.
This gives us a bit more insight into the workings of our program. In addition, we can now identify performance bottlenecks. The %hist
command shows the commands history.
I hope you agree that IPython is a really useful tool!