~$ 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中追加python
export PYTHONSTARTUP="~/.pythonstartup"shell
或bash
export PYTHONSTARTUP="$HOME/.pythonstartup"spa
source .bashrc使之生效命令行
這樣Python命令行就支持自動補全和記錄歷史命令的功能了code