Tab completion

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Apr 2 16:59:29 CEST 2009


Does anyone use the tab-completion recipe in the docs?

http://docs.python.org/library/rlcompleter.html#module-rlcompleter

suggests using this to enable tab-completion:

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

which is all very nice, but it makes it rather difficult to indent code 
blocks:

>>> def func(x):
...
Display all 174 possibilities? (y or n)


I like tab-completion, but I'd rather not be reduced to typing spaces for 
indents in the interpreter. What do other people do?

Can I bind Ctrl-tab to the completion instead of regular tab? I tried 
readline.parse_and_bind("C-tab: complete") but it still completes on 
regular tab.

The GNU readline library claims that M-tab (which I guess is Alt-tab) 
will enter a tab character. Problem is that Alt-tab is intercepted by my 
window manager for something else.

Any other suggestions or hints?

-- 
Steven



More information about the Python-list mailing list