当前位置: 首页 >> Python >> 【技巧】python linux tab自动补全和历史命令管理 >> 正文

【技巧】python linux tab自动补全和历史命令管理

8年前 (2016-02-23)     作者:Jiaozn     分类:Python     阅读次数:3770     评论(0)    

Python的startup文件,即环境变量 PYTHONSTARTUP 对应的文件 ,为readline添加tab键自动补全的功能,像Shell一样管理历史命令

  1. 安装readline模块。

sudo apt-get install readline*

2.创建文件~/.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

3.在~/.bash_profile中添加环境变量

export PYTHONSTARTUP=~/.pythonstartup

4.刷新配置

source .bash_profile


除非注明,发表在“Jiaozn的博客”的文章『【技巧】python linux tab自动补全和历史命令管理』版权归Jiaozn所有。 转载请注明出处为“本文转载于『Jiaozn的博客』原地址https://www.jiaozn.com/reed/233.html
0

评论

发表评论   

昵称*

E-mail*(建议输入,以便收到博主回复的提示邮件)

网站

分享:

支付宝

微信