IPython and doctests

Just discovered something really fantastic about ipython (well, besides all the cool stuff that was already there). It has some neat support for writing python doctests. If you press%doctest_mode, ipython flips into a different prompt that looks like a doctest, with the leading angle brackets. This mode allows you to paste doctest snippets without needing to remove the leading brackets first, and it will execute the code. This format also means you can interactively write doctests, and then copy/paste to a doctest file (perhaps deleting a few lines). There is also a neat function, IPython.dtutils.idoctest() that will let you paste a whole doctest, output and all, and it will execute it and tell you the results. Very useful for debugging doctests.

Since I can’t seem to post something lately without mentioning bzr and launchpad, here it is: IPython is using bazaar and launchpad! Great to have you guys using the service. How about setting up a PPA with a newer Ubuntu package that includes all this cool doctest support?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 450 other followers

%d bloggers like this: