我使用以下命令在python shell上启用历史记录。
这是我的 文件。PYTHONSTARTUP环境变量设置为此文件路径。
# python startup file
import readline
import rlcompleter
import atexit
import os
# tab completion
readline.parse_and_bind('tab: complete')
# history file
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter
您将需要使模块readline rlcompleter启用此功能。
在以下网址查看有关此信息:http : //docs.python.org/using/cmdline.html#envvar- PYTHONSTARTUP。
所需模块: