我最近在python interperter中发现了auto completetion:https://docs.python.org/2.7/tutorial/interactive.html。 这对于加速我在交互式解释器中所做的测试是非常好的。有两件事是可以完成的,它们都是有用的。你知道吗
如果我简单地将C+f: complete
放在我的.inputrc中(或者使用没有rlcompleter的readline),当我按下Ctl+f时,我会在启动解释器的目录中完成文件。当我加载模块readline
和rlcompleter
并将readline.parse_and_bind('C-n: complete')
添加到.pystartup文件时,它将Ctl+n和Ctl+f转换为自动完成的python对象。你知道吗
我想两者都做,但不确定如何防止rlcompleter
重写标准完成。有没有办法启动两个readline
实例,一个使用,一个不使用rlcompleter
?你知道吗
这是我的.pystartup文件
import atexit
import os
import readline
import rlcompleter #removing this does file completion.
readline.parse_and_bind('C-n: complete')
historyPath = os.path.expanduser("~/.pyhistory")
def save_history(historyPath=historyPath):
import readline
readline.write_history_file(historyPath)
if os.path.exists(historyPath):
readline.read_history_file(historyPath)
atexit.register(save_history)
del os, atexit, readline, rlcompleter, save_history, historyPath
工作原理:
导入
rlcompleter
时,它将rlcompleter.Completer().complete
安装为readline
的完成符:readline.set_completer(Completer().complete)
。你知道吗如果没有
rlcompleter
,completer
是None
,那么底层GNU readline lib默认使用rl_filename_completion_function
。你知道吗绑定键和完成逻辑是由GNU readline lib实现的,因此在Python中没有任何关于
start up two instances of readline
的操作。。。你知道吗我没有找到在Python中调用default
rl_filename_completion_function
的方法(在C扩展中是可能的),所以我想您必须在Python中复制rl_filename_completion_function
的逻辑。你知道吗这意味着您应该继承
Completer
并构建您的自定义complete
。但是您仍然不能将这两个逻辑拆分为C-n
和C-f
:(相关问题 更多 >
编程相关推荐