[Pythonmac-SIG] Retroactively adding readline support to OS X

Skip Montanaro skip at pobox.com
Thu Jun 26 09:41:36 EDT 2003


    calvin> I just downloaded this and ran it.  the build seems to go okay,
    calvin> but I still don't have readline...is there something I'm
    calvin> missing?  I've got readline.so in site-packages, but dang i wish
    calvin> I my up key worked.

You still need some magic in your PYTHONSTARTUP file.  This works for me and
gives you history across sessions to boot:

    try:
        import readline
    except ImportError:
        pass
    else:
        readline.parse_and_bind("tab: complete")
        if hasattr(readline, "read_history_file"):
            import os
            histfile = os.path.join(os.environ["HOME"], ".pyhist")
            try:
                readline.read_history_file(histfile)
            except IOError:
                pass
            import atexit
            atexit.register(readline.write_history_file, histfile)

At this point you can probably get rid of the hasattr() call unless you're
using an older version of Python (2.[01]ish or earlier).

Skip



More information about the Pythonmac-SIG mailing list