首页 > 代码库 > python环境tab命令自动补全

python环境tab命令自动补全

在用户目录下创建.pythonstartup文件,输入如下脚本

# python startup file
import sys
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


输入

export PYTHONSTARTUP=~/.pythonstartup


编辑用户目录下的.bash_profile,最后加入下列命令

export PYTHONSTARTUP=~/.pythonstartup


python环境tab命令自动补全