【发布时间】:2012-07-27 01:38:05
【问题描述】:
在python解释器中我们可以使用
readline.parse_and_bind('tab: complete')
启用标签补全
是否可以将任意键绑定到我们自己的函数?
我想分别将 CTRL+E 和 CTRL+SHIFT+E 绑定到 edit_history() 和 edit_history(True) ,其中 edit_history() 是我自己在 .pythonrc 中定义的函数
def edit_history(fork=False):
import readline
timeStamp = time.strftime("%Y%m%d-%H%M%S")
tmpFile = '/tmp/pyHistory.%s' % timeStamp
readline.write_history_file(tmpFile)
if not fork:
os.system('gvim -f %s' % tmpFile)
readline.clear_history()
readline.read_history_file(tmpFile)
os.unlink(tmpFile)
else:
os.system('gvim %s' % tmpFile)
任何指针将不胜感激
谢谢,
墙裙
【问题讨论】:
-
你应该看看像iPython这样的增强型解释器,它有很多有趣的
%magic。 -
感谢 Paulo 的建议,但我无法习惯 iPython。
标签: keyboard-shortcuts interpreter key-bindings python