Source code:
———
The rlcompleter module defines a completion function suitable to be passed to
in the
module.
When this module is imported on a Unix platform with the
module available, an instance of the
class is automatically created and its
method is set as the
. The method provides completion of valid Python
.
Example:
>>> importrlcompleter>>> importreadline>>> readline.parse_and_bind("tab: complete")>>> readline.<TABPRESSED>readline.__doc__ readline.get_line_buffer( readline.read_init_file(readline.__file__ readline.insert_text( readline.set_completer(readline.__name__ readline.parse_and_bind(>>> readline.The rlcompleter module is designed for use with Python’s
. Unless Python is run with the
option, the module is automatically imported and configured (see
).
On platforms without
, the
class defined by this module can still be used for custom purposes.
classrlcompleter.Completer
Completer objects have the following method:
complete(text, state)
Return the next possible completion for text.
When called by the
module, this method is called successively with state==0,1,2,... until the method returns None.
If called for text that doesn’t include a period character ('.'), it will complete from names currently defined in
,
and keywords (as defined by the
module).
If called for a dotted name, it will try to evaluate anything without obvious side-effects (functions will not be evaluated, but it can generate calls to
) up to the last part, and find matches for the rest via the
function. Any exception raised during the evaluation of the expression is caught, silenced and
is returned.