python学习--导入tab键自动补全功能的配置

.切换目录到python的安装目录下,进行tab键补全模块的编写


复制代码
[root@localhost ~]# cd /usr/lib64/python2.6
[root@localhost python2.6]# vim tab.py

#!/usr/bin/env python
复制代码
# 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
复制代码
复制代码

 注意:一定要安装上边代码的严格缩进来做,防止不生效。

进入家目录,编写 .bashrc文件在最后添加下面一行,保存退出。

[root@localhost ~]# cd ~

[root@localhost ~]# vim .bashrc

export PYTHONSTARTUP=/usr/lib64/python2.6/tab.py

 

家目录.bashrc文件只有用户登录时才会加载生效,需要进行下面的操作来生效

[root@localhost ~]# source .bashrc

 

那么现在就可以使用tab键补全功能了

posted @ 2018-03-14 13:26  wangyi429111  阅读(407)  评论(0编辑  收藏  举报