~$ cat .pythonstartup import os import readline import rlcompleter import atexit #tab completion readline.parse_and_bind("tab: complete") #history file history_file = os.path.join(os.environ["HOME"],".pythonhistory") try: readline.read_history_file(history_file) except IOError: pass atexit.register(readline.write_history_file,history_file) del os,history_file,readline,rlcompleter
.bashrc中追加
export PYTHONSTARTUP="~/.pythonstartup"
或
export PYTHONSTARTUP="$HOME/.pythonstartup"
source .bashrc使之生效
这样Python命令行就支持自动补全和记录历史命令的功能了