Python的自動補全

三角形發表於2016-08-30
1、編輯檔案 tab.py
 
 1 vi tab.py
 2  
 3 #!/usr/bin/env python
 4 # python startup file
 5 import sys
 6 import readline
 7 import rlcompleter
 8 import atexit
 9 import os
10 # tab completion
11 readline.parse_and_bind('tab: complete')
12 # history file
13 histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
14 try:
15     readline.read_history_file(histfile)
16 except IOError:
17     pass
18 atexit.register(readline.write_history_file, histfile)
19 del os, histfile, readline, rlcompleter
 
2、確認 第三方指令碼或模組存放路徑
 
1 [root@sun ~]# python
2 Python 2.7.12 (default, Aug 23 2016, 16:39:04)
3 [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
4 Type "help", "copyright", "credits" or "license" for more information.
5 >>> import sys
6 >>> sys.path
7 ['', '/usr/local/python27/lib/python27.zip', '/usr/local/python27/lib/python2.7', '/usr/local/python27/lib/python2.7/plat-linux2', '/usr/local/python27/lib/python2.7/lib-tk', '/usr/local/python27/lib/python2.7/lib-old', '/usr/local/python27/lib/python2.7/lib-dynload', '/usr/local/python27/lib/python2.7/site-packages']
8 >>>

 

3、將編輯好的 tab.py 指令碼放到  /usr/local/python27/lib/python2.7/site-packages 目錄一份
 
1 [root@sun ~]# cp tab.py /usr/local/python27/lib/python2.7/site-packages/
 
4、驗證結果
 
 1 [root@sun ~]# python
 2 Python 2.7.12 (default, Aug 23 2016, 16:39:04)
 3 [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
 4 Type "help", "copyright", "credits" or "license" for more information.
 5 >>> import tab
 6 >>> h
 7 hasattr(  hash(     help(     hex(     
 8 >>> h
 9 >>> s
10 set(           slice(         staticmethod(  sum(           
11 setattr(       sorted(        str(           super(
 
 

相關文章