Coder’s Eye

A site about one of the three passions in my life.

Coder’s Eye header image 2

IPython brings joy

February 14th, 2006 · 1 Comment

Jumping for joyAfter my rant yesterday, it is time to share another programming tool I find absolutely indispensable. IPython is an enhanced command-line shell for Python.

By itself, that may not sound like much, but you really get a lot. You get command history, tab-completion, and automatic introspection of classes. That means you can look up the specific code any function will call, at any time. It has all sorts of automatic and “magic” things it can do, all of which make it a must-try for the working Python programmer.

Yes, but what has it done for me lately?

Since installing IPython last year, I find myself using it for all sorts of tiny tasks which I would have done in a more fragile, cumbersome, or laborious way in the past. Last week, I needed to insert 50,000 records into a database. They were very simple insertions, so I could have just run an Emacs macro to do make all my Sql. But now with IPython, I just pop into a shell, load the unformatted records from a CSV file, and build the SQL in three lines or less of code. Sweet!.

Today, I needed to find the missing item in the haystack. I had two lists, one text and one from a database. The database was missing one of the items from the list. But which one? That was a trivial thing to conquer using a little 1 minute IPython session. Like so:

In [1]: f = open('cc_tables','r')
In [2]: tables = f.readlines()
In [3]: f.close()
In [4]: f = open('cc_list','r')
In [5]: dump = f.readlines()
In [6]: f.close()
In [7]: len(tables)
Out[7]: 104
In [8]: len(dump)
Out[8]: 103
In [9]: [x for x in tables if x not in dump]
Out[9]: ['DataExtractionStatus\n']

The answer, in 9 lines, 4 of which were unneeded, was “DataExtractionStatus”. I could’ve done that in OpenOffice Calc, but the thing would have still been loading in the time it took me to bang out the answer with IPython. Thank you IPython, for making my job that much easier and faster.

Technorati Tags: ,

Tags: Open Source · Python

Bookmark this article

del.icio.us:IPython brings joy digg:IPython brings joy spurl:IPython brings joy wists:IPython brings joy simpy:IPython brings joy newsvine:IPython brings joy blinklist:IPython brings joy furl:IPython brings joy reddit:IPython brings joy fark:IPython brings joy blogmarks:IPython brings joy Y!:IPython brings joy smarking:IPython brings joy magnolia:IPython brings joy segnalo:IPython brings joy gifttagging:IPython brings joy

1 response so far ↓

  • 1 import this. » Blog Archive » More praise for IPython // Feb 14, 2006 at 6:21 pm

    […] Quoth Bruce: Since installing IPython last year, I find myself using it for all sorts of tiny tasks which I would have done in a more fragile, cumbersome, or laborious way in the past. […]

Leave a Comment