En­hance Your Pro­gram­ming Ex­pe­ri­ence with IPython

Take learn­ing, teach­ing and com­put­ing with Python to a new level with this in­ter­ac­tive com­put­ing en­vi­ron­ment.

OpenSource For You - - DEVELOPERS -

Soft­ware de­vel­op­ment is a nu­anced ac­tiv­ity. Un­less you are do­ing legacy prod­uct main­te­nance—where there are se­vere re­stric­tions on cre­ativ­ity—you are re­ally learn­ing lan­guage mech­a­nisms, try­ing out al­go­rithms, tweak­ing com­pu­ta­tion mod­els, or shar­ing a cou­ple of pro­gram­ming recipes with your ju­niors. This is no sur­prise to those who have worked with for­mal it­er­a­tive de­vel­op­ment cy­cles or to stu­dents and sci­en­tists wrestling with data.

Python is a pop­u­lar lan­guage to learn and teach, and of course to pro­gram in. So, is there an en­vi­ron­ment that ex­poses the po­ten­tial of Python in a fun man­ner and also cre­ates an ecosys­tem for both teach­ers and learn­ers?

fPython is your an­swer. ft can be your favourite learn­ing, teach­ing or com­put­ing en­vi­ron­ment de­pend­ing on what your pri­mary pur­pose is. What you learn and de­velop in fPython can re­ally con­trib­ute to highly pro­duc­tive ses­sions with a for­mal f'E in the fi­nal stage of a de­vel­op­ment phase.

As­sum­ing you have Python al­ready in­stalled, in­stall

ipython and ipython-note­book us­ing your pack­age man­ager, and you are ready to go. oun the fol­low­ing com­mand:

$ ipython note­book

Your browser should open with a note­book dash­board where you can start a new note­book or open an ex­ist­ing one. (ff you are run­ning Python 3, the rec­om­mended down­load is ipython3.) In­tu­itive in­ter­ac­tion A typ­i­cal open note­book with code and out­put could look like what’s shown in Fig­ure 1. fPython is very well doc­u­mented and the place to learn more about this ex­cit­ing tool is the ipython.org web­site. But be­fore you get there, let us look at some ba­sic us­age that will take you well past the ‘Hello world’ stage.

fPython runs code in cells. A cell is a con­tainer for

a piece of code or text. The left pane of your note­book has but­tons that let you delete, in­sert or move cells around. The de­fault en­try mode into a cell is ‘code'; so you can go right ahead and en­ter the ‘Hello world’ code snippet. As you hit YEn­ter>, the cell grows in size, let­ting you en­ter more code. You have two modes to ex­e­cute your code. A <Ctrl> + <En­ter> ex­e­cutes your code in-place. Which means you could keep edit­ing the same piece of code to say ‘Hello' to all your friends by hit­ting <Ctrl> + <En­ter> to see the out­put in the same cell. There is no ex­e­cu­tion his­tory, and the cell holds the last piece of code you en­tered along with its out­put. A <Shift> + <En­ter> lets you run the code in the cell and opens a new cell for in­put. This way you have a his­tory of cell ex­e­cu­tions that might be lead­ing up to some pro­gram­ming goal you have set for your­self. Don't worry, you can al­ways delete the cells that do not fit in.

What is code with­out doc­u­men­ta­tion? You can switch a cell from the code to the text mode by se­lect­ing ‘mark­down' from the left pane. This op­tion lets you en­ter text in a cell us­ing the mark­down for­mat, which is sim­i­lar to the wiki syn­tax. The mark­down is ren­dered as HTML.

fPython lets you em­bed graphs and plots in line with your note­book. You could use Mat­plotlib or dNU Oc­tave to draw graphs that in­te­grate seam­lessly with your fPython note­book. There is tab com­ple­tion avail­able, too.

Then there are the sup­posed magic com­mands. Th­ese get you some ‘meta' func­tion­al­ity. For in­stance:

%timeit -n10 -r5 print "Hello World"

…would time the state­ment for you over 10 it­er­a­tions, tak­ing the best of five. A %ls­magic will get you all the magic com­mands avail­able to you. To get help on a magic com­mand, you just need to is­sue the magic com­mand ap­pended by a '?' mark. A %book­mark? com­mand would give you help on fPython's book­mark com­mand, for in­stance.

For the sci­en­tific types, there is sup­port for em­bed­ding graphs as men­tioned ear­lier. One way to learn how to do this is to is­sue the %py­lab in­line com­mand be­fore try­ing out the ter­rific tu­to­ri­als on the fPython site.

By now you might also have no­ticed the Print com­mand in the left pane, and have also tried print­ing your note­book. This works very much like print­ing any HTML page, which means you can also save your note­book to a PDF file.

Fig­ure 1: An open note­book with code and out­put

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.