Source code:Lib/rlcompleter.py
Therlcompleter module defines a completion function suitable for thereadline module by completing valid Python identifiers and keywords.
When this module is imported on a Unix platform with thereadline moduleavailable, an instance of theCompleter class is automatically createdand itscomplete() method is set as thereadline completer.
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.
Therlcompleter module is designed for use with Python’s interactivemode. A user can add the following lines to his or her initialization file(identified by thePYTHONSTARTUP environment variable) to getautomaticTab completion:
try:importreadlineexceptImportError:print("Module readline not available.")else:importrlcompleterreadline.parse_and_bind("tab: complete")
On platforms withoutreadline, theCompleter class defined bythis module can still be used for custom purposes.
Completer objects have the following method:
Return thestateth completion fortext.
If called fortext that doesn’t include a period character ('.'), it willcomplete from names currently defined in__main__,builtins andkeywords (as defined by thekeyword module).
If called for a dotted name, it will try to evaluate anything without obviousside-effects (functions will not be evaluated, but it can generate calls to__getattr__()) up to the last part, and find matches for the rest via thedir() function. Any exception raised during the evaluation of theexpression is caught, silenced andNone is returned.
6.7.readline — GNU readline interface
Enter search terms or a module, class or function name.