小编典典
当然可以,只需一个小的启动脚本。从交互式输入编辑及历史替换在Python教程:
# Add auto-completion and a stored history file of commands to your Python
# interactive interpreter. Requires Python 2.0+, readline. Autocomplete is
# bound to the Esc key by default (you can change it - see readline docs).
#
# Store the file in ~/.pystartup, and set an environment variable to point
# to it: "export PYTHONSTARTUP=~/.pystartup" in bash.
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)
atexit.register(save_history)
del os, atexit, readline, rlcompleter, save_history, historyPath
现在,在支持的系统上的交互式解释器中,默认情况下启用了制表符完成功能readline。默认情况下,历史记录也处于启用状态,并且被写入文件(或从文件中读取)~/.python-
history。
2020-06-02