我在 linux 中使用下面的 pystartup 脚本来使 REPL Python 中的选项卡上的历史记录和自动完成功能可用。我已经切换到 OSX 并且我已经修改了脚本,以便选项卡完成工作。但我无法弄清楚如何使搜索工作?搜索几个 SO 问题,例如 Python 交互模式历史和箭头键
但我不想卸载 OSX 附带的 python 版本,因为它可能会导致其他一些依赖关系破坏。
我的 python 版本是 2.7.10
脚本
import atexit
import os
import readline
import rlcompleter
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)
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete")
readline.set_history_length(1000)
atexit.register(readline.write_history_file, historyPath)
atexit.register(save_history)
del os, atexit, readline, rlcompleter, save_history, historyPath
