python tab 自动补全

环境Centos6.5   python2.6.6

 

1、编写python的tab自动补全脚本

 

#!/usr/bin/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

2、查看python默认的模块存放路径

 

>>> sys.path
['', '/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/gst-0.10', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib/python2.6/site-packages']

3、将 tab.py 拷贝到 默认的模块存放路径

cp  tab.py  /usr/lib/python2.6/site-packages/

ln -s ~/tab.py  /usr/lib/python2.6/site-packages/

 

4、使用

>>> import sys
>>> import tab
>>> sys.
sys.__class__( sys.__reduce_ex__( sys.builtin_module_names sys.exitfunc( sys.maxsize sys.setprofile(
sys.__delattr__( sys.__repr__( sys.byteorder sys.flags sys.maxunicode sys.setrecursionlimit(
sys.__dict__ sys.__setattr__( sys.call_tracing( sys.float_info sys.meta_path sys.settrace(
sys.__displayhook__( sys.__sizeof__( sys.callstats( sys.getcheckinterval( sys.modules sys.stderr
sys.__doc__ sys.__stderr__ sys.copyright sys.getdefaultencoding( sys.path sys.stdin
sys.__excepthook__( sys.__stdin__ sys.displayhook( sys.getdlopenflags( sys.path_hooks sys.stdout
sys.__format__( sys.__stdout__ sys.dont_write_bytecode sys.getfilesystemencoding( sys.path_importer_cache sys.subversion
sys.__getattribute__( sys.__str__( sys.exc_clear( sys.getprofile( sys.platform sys.version
sys.__hash__( sys.__subclasshook__( sys.exc_info( sys.getrecursionlimit( sys.prefix sys.version_info
sys.__init__( sys._clear_type_cache( sys.exc_type sys.getrefcount( sys.ps1 sys.warnoptions
sys.__name__ sys._current_frames( sys.excepthook( sys.getsizeof( sys.ps2
sys.__new__( sys._getframe( sys.exec_prefix sys.gettrace( sys.py3kwarning
sys.__package__ sys.api_version sys.executable sys.hexversion sys.setcheckinterval(
sys.__reduce__( sys.argv sys.exit( sys.maxint sys.setdlopenflags(

 

 

 

你可能感兴趣的:(python tab 自动补全)