python自动补全

1.编辑tab补全功能文件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

2.查看python环境中的路径
[root@aliyun python]# python
Python 2.7.5 (default, Nov  6 2016, 00:28:07) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib/python2.7/site-packages', '/usr/lib/python2.7/site-packages/cloud_init-0.7.6-py2.7.egg']

3.移动tab.py到python环境路径
mv tab.py /usr/lib/python2.7/site-packages

4.导入tab,导入sys测试
[root@aliyun python]# python 
Python 2.7.5 (default, Nov  6 2016, 00:28:07) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tab
>>> import sys
>>> print sys.
sys.__class__(              sys.__name__                sys.__stdout__              sys.builtin_module_names    sys.excepthook(             sys.getdlopenflags(         sys.maxsize                 sys.ps2                     sys.stdout
sys.__delattr__(            sys.__new__(                sys.__str__(                sys.byteorder               sys.exec_prefix             sys.getfilesystemencoding(  sys.maxunicode              sys.py3kwarning             sys.subversion
sys.__dict__                sys.__package__             sys.__subclasshook__(       sys.call_tracing(           sys.executable              sys.getprofile(             sys.meta_path               sys.pydebug                 sys.version
sys.__displayhook__(        sys.__reduce__(             sys._clear_type_cache(      sys.callstats(              sys.exit(                   sys.getrecursionlimit(      sys.modules                 sys.setcheckinterval(       sys.version_info
sys.__doc__                 sys.__reduce_ex__(          sys._current_frames(        sys.copyright               sys.exitfunc(               sys.getrefcount(            sys.path                    sys.setdlopenflags(         sys.warnoptions
sys.__excepthook__(         sys.__repr__(               sys._debugmallocstats(      sys.displayhook(            sys.flags                   sys.getsizeof(              sys.path_hooks              sys.setprofile(             
sys.__format__(             sys.__setattr__(            sys._getframe(              sys.dont_write_bytecode     sys.float_info              sys.gettrace(               sys.path_importer_cache     sys.setrecursionlimit(      
sys.__getattribute__(       sys.__sizeof__(             sys._mercurial              sys.exc_clear(              sys.float_repr_style        sys.hexversion              sys.platform                sys.settrace(               
sys.__hash__(               sys.__stderr__              sys.api_version             sys.exc_info(               sys.getcheckinterval(       sys.long_info               sys.prefix                  sys.stderr                  
sys.__init__(               sys.__stdin__               sys.argv                    sys.exc_type                sys.getdefaultencoding(     sys.maxint                  sys.ps1                     sys.stdin                   
>>> exit()

5.配置自动导入文件,并导入配置
echo "export PYTHONSTARTUP=/usr/lib/python2.7/site-packages/tab.py" >>~/.bashrc
source ~/.bashrc