rlcompleter
— Completion function for GNU readlineGNU readline的完成功能¶
Source code: Lib/rlcompleter.py
The rlcompleter
module defines a completion function suitable for the readline
module by completing valid Python identifiers and keywords.rlcompleter
模块通过完成有效的Python标识符和关键字来定义适合readline
模块的完成函数。
When this module is imported on a Unix platform with the 在Unix平台上导入此模块时,如果readline
module available, an instance of the Completer
class is automatically created and its complete()
method is set as the readline
completer.readline
模块可用,则会自动创建Completer
类的实例,并将其complete()
方法设置为readline
补全器。
Example:
>>> import rlcompleter
>>> import readline
>>> readline.parse_and_bind("tab: complete")
>>> readline. <TAB PRESSED>
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 interactive mode. rlcompleter
模块设计用于Python的交互模式。Unless Python is run with the 除非Python使用-S
option, the module is automatically imported and configured (see Readline configuration).-S
选项运行,否则会自动导入和配置模块(请参阅Readline配置)。
On platforms without 在没有readline
, the Completer
class defined by this module can still be used for custom purposes.readline
的平台上,此模块定义的Completer
类仍然可以用于自定义目的。
Completer Objects完成符对象¶
Completer objects have the following method:完成符对象具有以下方法:
-
Completer.
complete
(text, state)¶ Return the stateth completion for text.返回text的第state次补全。If called for text that doesn’t include a period character (如果为不包含句点字符('.'
), it will complete from names currently defined in__main__
,builtins
and keywords (as defined by thekeyword
module).'.'
)的text调用,它将从当前在__main__
中定义的名称、builtins
和关键字(由关键字模块定义)完成。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如果调用虚线名称,它将尝试评估没有明显副作用的任何内容(不会评估函数,但它可以生成对__getattr__()
) up to the last part, and find matches for the rest via thedir()
function.__getattr__()
的调用),直到最后一部分,并通过dir()
函数查找其余部分的匹配项。Any exception raised during the evaluation of the expression is caught, silenced and在表达式求值期间引发的任何异常都将被捕获、静默,并且会返回None
is returned.None
。