[Python-ideas] Enable tab completion for interactive sessions

Christian Heimes lists at cheimes.de
Sun Nov 11 21:43:27 CET 2007


Hello fellow Pythonistas!

Python has a very useful feature a lot of people don't know about. It's
tab completion for the interactive shell.
http://docs.python.org/lib/module-rlcompleter.html

Tab completion is very useful for introspection and quick tests in an
interactive shell. rlcompleter isn't enable by default - and it
shouldn't. But I like to add a cmd line option and an env var to load
and enable the rlcompleter in an interactive session.

The right place to enable the feature is in

Modules/main.c:460
if ((Py_InspectFlag || (command == NULL && filename == NULL && module ==
NULL)) && isatty(fileno(stdin))) {

    code run when -i is given or neither command nor filename nor module
is set and stdin is an interactive terminal.

}

At the moment the code block loads just the readline module. I also like
to load the rlcompleter module and invoke readline.parse_and_bind("tab:
complete") there.

Options:
(1) always enable tab completion for interactive shells w/o a command,
module and filename.
(2) only enable rlcompleter when the -i flag or PYTHONINTERACTIVE env
var is set.
(3) add a new command flag and env var to enable the completer when (1)
or (2) is true

Christian




More information about the Python-ideas mailing list