Python的自动补全

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(
 
 
posted @ 2016-08-30 11:11  三角形  阅读(1429)  评论(0编辑  收藏  举报