`
scm002
  • 浏览: 309311 次
社区版块
存档分类
最新评论

给python交互式命令行增加自动补全和命令历史

 
阅读更多
  • 在用户目录下新建".pythonstartup"文件,写入以下内容:
复制代码
# python startup file
import readline
import rlcompleter
import atexit
import os
#tab completion
readline.parse_and_bind('tab: complete')
#history file
historyfile = os.path.join(os.environ['HOME'],'.pythonstartup')
try:
    readline.read_history_file(historyfile)
except:
    pass
atexit.register(readline.write_history_file,historyfile)
del os,historyfile,readline,rlcompleter
复制代码

 

  • 增加环境变量,编辑.bashrc或.zshrc文件(根据你的shell确定),加入以下内容:
export PYTHONSTARTUP="/home/ma6174/.pythonstartup"
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics