Enhance Your Programming Experience with IPython
Take learning, teaching and computing with Python to a new level with this interactive computing environment.
Software development is a nuanced activity. Unless you are doing legacy product maintenance—where there are severe restrictions on creativity—you are really learning language mechanisms, trying out algorithms, tweaking computation models, or sharing a couple of programming recipes with your juniors. This is no surprise to those who have worked with formal iterative development cycles or to students and scientists wrestling with data.
Python is a popular language to learn and teach, and of course to program in. So, is there an environment that exposes the potential of Python in a fun manner and also creates an ecosystem for both teachers and learners?
fPython is your answer. ft can be your favourite learning, teaching or computing environment depending on what your primary purpose is. What you learn and develop in fPython can really contribute to highly productive sessions with a formal f'E in the final stage of a development phase.
Assuming you have Python already installed, install
ipython and ipython-notebook using your package manager, and you are ready to go. oun the following command:
$ ipython notebook
Your browser should open with a notebook dashboard where you can start a new notebook or open an existing one. (ff you are running Python 3, the recommended download is ipython3.) Intuitive interaction A typical open notebook with code and output could look like what’s shown in Figure 1. fPython is very well documented and the place to learn more about this exciting tool is the ipython.org website. But before you get there, let us look at some basic usage that will take you well past the ‘Hello world’ stage.
fPython runs code in cells. A cell is a container for
a piece of code or text. The left pane of your notebook has buttons that let you delete, insert or move cells around. The default entry mode into a cell is ‘code'; so you can go right ahead and enter the ‘Hello world’ code snippet. As you hit YEnter>, the cell grows in size, letting you enter more code. You have two modes to execute your code. A <Ctrl> + <Enter> executes your code in-place. Which means you could keep editing the same piece of code to say ‘Hello' to all your friends by hitting <Ctrl> + <Enter> to see the output in the same cell. There is no execution history, and the cell holds the last piece of code you entered along with its output. A <Shift> + <Enter> lets you run the code in the cell and opens a new cell for input. This way you have a history of cell executions that might be leading up to some programming goal you have set for yourself. Don't worry, you can always delete the cells that do not fit in.
What is code without documentation? You can switch a cell from the code to the text mode by selecting ‘markdown' from the left pane. This option lets you enter text in a cell using the markdown format, which is similar to the wiki syntax. The markdown is rendered as HTML.
fPython lets you embed graphs and plots in line with your notebook. You could use Matplotlib or dNU Octave to draw graphs that integrate seamlessly with your fPython notebook. There is tab completion available, too.
Then there are the supposed magic commands. These get you some ‘meta' functionality. For instance:
%timeit -n10 -r5 print "Hello World"
…would time the statement for you over 10 iterations, taking the best of five. A %lsmagic will get you all the magic commands available to you. To get help on a magic command, you just need to issue the magic command appended by a '?' mark. A %bookmark? command would give you help on fPython's bookmark command, for instance.
For the scientific types, there is support for embedding graphs as mentioned earlier. One way to learn how to do this is to issue the %pylab inline command before trying out the terrific tutorials on the fPython site.
By now you might also have noticed the Print command in the left pane, and have also tried printing your notebook. This works very much like printing any HTML page, which means you can also save your notebook to a PDF file.
Figure 1: An open notebook with code and output