Python, Mac OS X, and Readline.
Due to the political manifesto that is the GPL, Python on Mac OS X does not ship with the readline module.
This is hugely annoying. Interactive command line python is pretty close to useless without basic history and editing commands.
It is easy enough to fix. Would be easier if I didn’t also want to use the latest libreadline; version 5.1.
Either mount this in the Finder or:
svn co http://svn.red-bean.com/bbum/trunk/pyreadline/
From there, follow the instructions in the README. It definitely works with the stock Python on Mac OS X Intel. Should work for PPC, too.
It will likely also work for Python 2.4, but I haven’t tested it. If not, copying the readline.c from Python 2.4 into the readline-0.0.0 directory.
As Paul said, check out iPython. It offers an incredible interactive mode with full blown object introspection, including integrated documentation. I use it when I remember (thanks fro the reminder), but I also avoid it when doing examples for others or generating doctest test cases.
Revisions:
- added iPython info
- fixed stupid typo


March 7th, 2006 at 12:20 am
Hello,
Instead of adding readline to Python, try IPython instead:
http://ipython.scipy.org/
It’s an interpreter for python that supports readline, tab-completion for method names, colors, etc.
It’s great for testing stuff out!
March 7th, 2006 at 12:38 am
iPython is pretty amazing, but it is also considerably more complex than and adds a lot of verbosity over the standard python command line. I seem to end up switching back and forth between the two (when I remember to use ipython).
Unless I’m mistaken, you can’t use iPython to generate doctest compatible tests. doctest is just too cool; go to the interactive prompt, interact with your objects, save the transcript somewhere, remove any garbage, and feed it all through doctest to ensure that the test behaves the same in the future….
March 7th, 2006 at 12:42 am
After the “hugely annoying” in the intro, when you wrote: “Would be easier if I didn’t also want to sue the latest libreadline”, I actually thought you were talking about legal action.
Then I realized it was just a typo.
March 7th, 2006 at 12:51 pm
easy_install readline
easy_install ipython
March 7th, 2006 at 1:12 pm
What about libedit, the NetBSD readline replacement that ships with Darwin? Can Python be built to use it?
March 7th, 2006 at 1:41 pm
Thanks for introducing me to doctest! Finally, an easy way to write simple unit tests without resorting to the unittest module.
You’re right, IPython’s output doesn’t look like the output from a standard Python interpreter, so it is incompatible with doctest docstrings. But it’s so convenient for getting the lowdown on modules/classes etc.
Instead of ‘dir(objname)’, you can just type ‘objname.’ and you get a list of methods. To find out how to use a method, all you have to do is type ‘objname.method?’ and the object dictionary, method signature, and docstring pops out. The exception messages in IPython are also more descriptive than in the standard Python interpreter.
But you’re right. The Python interpreter comes standard with every Python installation and it’s easy to use. Guido himself prefers the standard interpreter to IPython.
http://video.google.com/videosearch?q=guido+van+rossum
March 24th, 2006 at 1:31 am
[...] Furthermore, I can use appscript from within the command line interpreter (read this first to make sure the command line python interpreter is actually useful). [...]
April 28th, 2006 at 1:14 am
Thanks for this tip on getting history for the command line python. not having this was driving me bonkers!
May 31st, 2006 at 12:17 pm
Thank you for that. I just got a Intel iMac and realised that I was going to have to finally update my Python readline implementation from way-back. Now I don’t need to! Thank you BBum!
July 1st, 2007 at 1:25 pm
[...] Bumgarner on fixing readline support in Mac Python. I’ve never run into this as I use the fine packages over at pythonmac.org; a lot of my code [...]
August 29th, 2007 at 8:10 am
Thankyou, following the readme worked like a charm on my macbook pro with Python 2.4.3.