ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](binary.xhtml "二进制数据服务") | - [上一页](readline.xhtml "readline --- GNU readline interface") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python 标准库](index.xhtml) » - [文本处理服务](text.xhtml) » - $('.inline-search').show(0); | # [`rlcompleter`](#module-rlcompleter "rlcompleter: Python identifier completion, suitable for the GNU readline library.") --- GNU readline的完成函数 **源代码:** [Lib/rlcompleter.py](https://github.com/python/cpython/tree/3.7/Lib/rlcompleter.py) \[https://github.com/python/cpython/tree/3.7/Lib/rlcompleter.py\] - - - - - - `rlcompeleter` 通过补全有效的 Python 标识符和关键字为 [`readline`](readline.xhtml#module-readline "readline: GNU readline support for Python. (Unix)") 模块定义了一个补全功能套装. 当此模块在具有可用的 [`readline`](readline.xhtml#module-readline "readline: GNU readline support for Python. (Unix)") 模块的 Unix 平台被导入, 一个 `Completer` 实例将被自动创建并且它的 `complete()` 方法将设置为 [`readline`](readline.xhtml#module-readline "readline: GNU readline support for Python. (Unix)") 的补全器. 示例: ``` >>> 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. ``` [`rlcompleter`](#module-rlcompleter "rlcompleter: Python identifier completion, suitable for the GNU readline library.") 模块是为了使用 Python 的 [交互模式](../tutorial/interpreter.xhtml#tut-interactive) 而设计的. 除非 Python 是通过 [`-S`](../using/cmdline.xhtml#id3) 选项运行, 这个模块总是自动地被导入且配置(参考 [Readline configuration](site.xhtml#rlcompleter-config)). 在没有 [`readline`](readline.xhtml#module-readline "readline: GNU readline support for Python. (Unix)") 的平台, 此模块定义的 `Completer` 类仍然可以用于自定义行为. ## Completer对象 Completer对象具有以下方法: `Completer.``complete`(*text*, *state*)为 *text* 返回 *state*th 补全. 如果要求 *text* 不包含句点字符 (`'.'`), 它将从当前定义的名称中完成 [`__main__`](__main__.xhtml#module-__main__ "__main__: The environment where the top-level script is run."), [`builtins`](builtins.xhtml#module-builtins "builtins: The module that provides the built-in namespace.") 和 keywords (就和通过 [`keyword`](keyword.xhtml#module-keyword "keyword: Test whether a string is a keyword in Python.") 模块定义的一样). 如果为加点的名称执行调用,它将尝试尽量求值直到最后一部分为止而不产生附带影响(函数不会被求值,但它可以生成对 [`__getattr__()`](../reference/datamodel.xhtml#object.__getattr__ "object.__getattr__") 的调用),并通过 [`dir()`](functions.xhtml#dir "dir") 函数来匹配剩余部分。 在对表达式求值期间引发的任何异常都会被捕获、静默处理并返回 [`None`](constants.xhtml#None "None")。 ### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](binary.xhtml "二进制数据服务") | - [上一页](readline.xhtml "readline --- GNU readline interface") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python 标准库](index.xhtml) » - [文本处理服务](text.xhtml) » - $('.inline-search').show(0); | © [版权所有](../copyright.xhtml) 2001-2019, Python Software Foundation. Python 软件基金会是一个非盈利组织。 [请捐助。](https://www.python.org/psf/donations/) 最后更新于 5月 21, 2019. [发现了问题](../bugs.xhtml)? 使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 创建。