[TriZPUG] Tab completion in python shell

Luke Campagnola luke.campagnola at gmail.com
Tue Apr 7 00:06:54 CEST 2015


Here's the script I use. It seems to work equally well in python 2 and 3:

import atexit
import os

historyPath = os.path.expanduser("~/.pyhistory")

try:
    import readline
except ImportError:
    print("Module readline not available.")
else:
    import rlcompleter
    readline.parse_and_bind("tab: complete")
    if os.path.exists(historyPath):
        readline.read_history_file(historyPath)

    def save_history(historyPath=historyPath):
        readline.write_history_file(historyPath)

    atexit.register(save_history)


I put this in ~/.pythonrc.py and set the PYTHONSTARTUP environment variable
to point to it.

On Mon, Apr 6, 2015 at 4:02 PM, Joseph S. Tate <dragonstrider at gmail.com>
wrote:

> I've been using rlcompleter2 for a long time for nice tab completion
> in the interactive python shell, but it turns out to not work under
> python3. What do other people use? What am I missing out on? Do I just
> need to train myself to type "ipython" when I want the interactive
> interpreter?
>
> --
> Joseph Tate
> _______________________________________________
> TriZPUG mailing list
> TriZPUG at python.org
> https://mail.python.org/mailman/listinfo/trizpug
> http://trizpug.org is the Triangle Zope and Python Users Group
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/trizpug/attachments/20150406/c94fc31b/attachment.html>


More information about the TriZPUG mailing list