python的tab自动补全

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



代码有了,我们还需要将脚本放到python指定的目录下,可以使用sys.path来查看一下

>>> sys.path
['', '/usr/lib/python2.6/site-packages/pip-7.1.2-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/site-packages/setuptools-0.6c11-py2.6.egg-info']
>>> sys
sys
>>> sys.
sys.__class__(              sys.__repr__(               sys.copyright               sys.getprofile(             sys.prefix
sys.__delattr__(            sys.__setattr__(            sys.displayhook(            sys.getrecursionlimit(      sys.ps1
sys.__dict__                sys.__sizeof__(             sys.dont_write_bytecode     sys.getrefcount(            sys.ps2
sys.__displayhook__(        sys.__stderr__              sys.exc_clear(              sys.getsizeof(              sys.py3kwarning
sys.__doc__                 sys.__stdin__               sys.exc_info(               sys.gettrace(               sys.setcheckinterval(
sys.__egginsert             sys.__stdout__              sys.exc_type                sys.hexversion              sys.setdlopenflags(
sys.__excepthook__(         sys.__str__(                sys.excepthook(             sys.last_type(              sys.setprofile(
sys.__format__(             sys.__subclasshook__(       sys.exec_prefix             sys.last_value              sys.setrecursionlimit(
sys.__getattribute__(       sys._clear_type_cache(      sys.executable              sys.maxint                  sys.settrace(
sys.__hash__(               sys._current_frames(        sys.exit(                   sys.maxsize                 sys.stderr
sys.__init__(               sys._getframe(              sys.exitfunc(               sys.maxunicode              sys.stdin
sys.__name__                sys.api_version             sys.flags                   sys.meta_path               sys.stdout
sys.__new__(                sys.argv                    sys.float_info              sys.modules                 sys.subversion
sys.__package__             sys.builtin_module_names    sys.getcheckinterval(       sys.path                    sys.version
sys.__plen                  sys.byteorder               sys.getdefaultencoding(     sys.path_hooks              sys.version_info
sys.__reduce__(             sys.call_tracing(           sys.getdlopenflags(         sys.path_importer_cache     sys.warnoptions
sys.__reduce_ex__(          sys.callstats(              sys.getfilesystemencoding(  sys.platform

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

 

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

ok,下面我们可以直接导入tab模块