vim tab.py
-------------------------------------
#!/usr/bin/env python
# python startup file 
import sysimport readline
import rlcompleter
import atexitimport 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指定的目录下,可以使用sys.path来查看一下


>>> import sys
]>>> sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']

 一般我们会将这一类代码放在/usr/local/lib/python2.7/dist-packages目录下

 

mv tab.py /usr/local/lib/python2.7/dist-packages

ok,下面我们可以直接导入tab模块,马上体验一下tab补全吧.....

  

>>> import tab>>> sys.sys.__class__(              sys.__subclasshook__(       sys.exitfunc(               sys.path_importer_cache
sys.__delattr__(            sys._clear_type_cache(      sys.flags                   sys.platform
sys.__dict__                sys._current_frames(        sys.float_info              sys.prefix
sys.__displayhook__(        sys._getframe(              sys.float_repr_style        sys.ps1
sys.__doc__                 sys._mercurial              sys.getcheckinterval(       sys.ps2
sys.__excepthook__(         sys._multiarch              sys.getdefaultencoding(     sys.py3kwarning
sys.__format__(             sys.api_version             sys.getdlopenflags(         sys.py

原文连接:http://www.mincoder.com/article/3884.shtml