[OS X 10.5] hitting TAB inserts ./ in interactive mode ?

Ned Deily nad at acm.org
Sat Sep 18 06:01:47 CEST 2010


In article 
<431250b2-391e-4a1f-ba72-08afb7159d65 at l25g2000prn.googlegroups.com>,
 Nik Krumm <nkrumm at gmail.com> wrote:
> Thanks for your help. I installed python 2.7 on my Mac OS X 10.5.8
> machine:
> 
> 
> nik$ python
> Python 2.7 (r27:82508, Jul  3 2010, 21:12:11)
> [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> 
> and now, when I hit TAB or paste in a code snippet with tabs in them,
> the interpreter tries to autocomplete a path, or inserts "./" if the
> line is blank (just as readline would in the shell environment). It
> does *not* try to autocomplete function (as readline would in python--
> importing readline does turn on this functionality). And it does *not*
> insert a tab, as I would like it to!

See the rlcompleter module in the standard library:
http://docs.python.org/library/rlcompleter.html

In my .bashrc file, I have a line:
    [ -f ~/.pythonrc ]  && export PYTHONSTARTUP=~/.pythonrc

and in the .pythonrc file, I include:

    try:
        import readline
    except ImportError:
        print("Module readline not available.")
    else:
        import rlcompleter
        readline.parse_and_bind("tab: complete")

Note the print() form which works with either Python 2 or 3.

-- 
 Ned Deily,
 nad at acm.org




More information about the Python-list mailing list