(一)系统环境:

 OS:centos 6.5final

 Python: 2.6.6


 (二)步骤:


1,写一个Python自动补全脚本首先readline和rlcompleter模块具体如下:,

[root@zabbix python2.6]# vim tab.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/python 
# python TAB 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


2,查看Python默认的模块的存放路径,有下可知默认的路径/usr/lib/python2.6/

1
2
3
4
5
6
7
8
[root@zabbix ~] # python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type  "help" "copyright" "credits"  or  "license"  for  more  information.
>>>  import  sys
>>> sys.path
[ '' '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg' '/usr/lib/python2.6/site-packages/pip-1.5.4-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/lib64/python2.6/site-packages/gtk-2.0' '/usr/lib/python2.6/site-packages' ]
>>>

默认的路径/usr/lib/python2.6/


3,拷贝上边的脚本到该路径下

1
[root@zabbix site-packages] # cp tab.py /usr/lib/python2.6/

4,导入该模块即可以使用了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
>>>  import  tab
>>> sys.
sys.__class__(              sys.api_version             sys.hexversion
sys.__delattr__(            sys.argv                    sys.maxint
sys.__dict__                sys.builtin_module_names    sys.maxsize
sys.__displayhook__(        sys.byteorder               sys.maxunicode
sys.__doc__                 sys.call_tracing(           sys.meta_path
sys.__egginsert             sys.callstats(              sys.modules
sys.__excepthook__(         sys.copyright               sys.path
sys.__format__(             sys.displayhook(            sys.path_hooks
sys.__getattribute__(       sys.dont_write_bytecode     sys.path_importer_cache
sys.__hash__(               sys.exc_clear(              sys.platform
sys.__init__(               sys.exc_info(               sys.prefix
sys.__name__                sys.exc_type                sys.ps1
sys.__new__(                sys.excepthook(             sys.ps2
sys.__package__             sys.exec_prefix             sys.py3kwarning