May 17, 2012

IPython brings joy

jump joy IPython brings 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.

[tags]Ipython,python[/tags]

Share and Enjoy:
  • services sprite IPython brings joy
  • services sprite IPython brings joy
  • services sprite IPython brings joy
  • services sprite IPython brings joy
  • services sprite IPython brings joy
  • services sprite IPython brings joy
  • services sprite IPython brings joy
  • services sprite IPython brings joy

Related posts:

  1. Helpful Django utilities and links Two simple links which have been very helpful in doing...

About Bruce Kroeze

Comments

Trackbacks

  1. [...] 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. [...]

Speak Your Mind

*