一、查看Python安裝路徑
[root@controller ~]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib/python2.7/site-packages']
二、切換目錄到python的安裝目錄下,進行tab鍵補全模塊的編寫
[root@controller ~]# cd /usr/lib64/python2.7/
[root@controller python2.7]# 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
三、避免進入python之后,不用每次都導入tab模塊
###進入家目錄,編寫 .bashrc文件在最后添加下面一行,保存退出###
[root@controller ~]#vim .bashrc
export PYTHONSTARTUP=/usr/lib64/python2.7/tab.py
###家目錄.bashrc文件只有用戶登錄時才會加載生效,需要進行下面的操作來生效###
[root@controller ~]#source .bashrc
OK,那么現在我們就可以不用每次進行python之后進行import tab 動作來使tab鍵補全功能生效了。