rlcompleter
--- GNU readline 的補全函式¶
Therlcompleter
module defines a completion function suitable to bepassed toset_completer()
in thereadline
module.
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. The method providescompletion of valid Pythonidentifiers and keywords.
範例:
>>>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'sinteractive mode. Unless Python is run with the-S
option, the module is automatically imported and configured(seeReadline configuration).
On platforms withoutreadline
, theCompleter
class defined bythis module can still be used for custom purposes.
- classrlcompleter.Completer¶
Completer objects have the following method:
- complete(text,state)¶
Return the next possible completion fortext.
When called by the
readline
module, this method is calledsuccessively withstate==0,1,2,...
until the method returnsNone
.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 therest via thedir()
function. Any exception raised during theevaluation of the expression is caught, silenced andNone
isreturned.