python學習筆記--導入tab鍵自動補全功能的配置


今天開始學習Python,必須配置tab鍵補全功能

1.首先我們需要查看python的安裝路徑

[root@abc ~]# python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python2.6/site-packages/cloud_init-0.7.6-py2.6.egg', '/usr/lib/python2.6/site-packages/jsonpatch-1.13-py2.6.egg', '/usr/lib/python2.6/site-packages/requests-2.9.1-py2.6.egg', '/usr/lib/python2.6/site-packages/argparse-1.4.0-py2.6.egg', '/usr/lib/python2.6/site-packages/Jinja2-2.8-py2.6.egg', '/usr/lib/python2.6/site-packages/jsonpointer-1.10-py2.6.egg', '/usr/lib/python2.6/site-packages/six-1.10.0-py2.6.egg', '/usr/lib/python2.6/site-packages/AliyunUtil-0.0.1-py2.6.egg', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info']

 


2.切換目錄到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鍵補全功能了



打賞

免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2022 CODEPRJ.COM