首先,要找到Python的路径
[hfrznew@recog1 python2.6]$ python
Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib64/python2.6', '/home/hfrznew/intedio/python', '/usr/lib64/python26.zip', '/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/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info']
>>>
切换到目录/usr/lib64/python2.6新建文件vim tab.py
#!/usr/bin/env python
#python startup file
import sys
import readline
import rlcompleter
import atexit
import os
#tab comletion
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
然后就可以在命令行里面用TAB键来补全了
[hfrznew@recog1 python2.6]$ python
Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tab
>>> import sys
>>> sys.
sys.__class__( sys.__setattr__( sys.copyright sys.getfilesystemencoding( sys.prefix
sys.__delattr__( sys.__sizeof__( sys.displayhook( sys.getprofile( sys.ps1
sys.__dict__ sys.__stderr__ sys.dont_write_bytecode sys.getrecursionlimit( sys.ps2
sys.__displayhook__( sys.__stdin__ sys.exc_clear( sys.getrefcount( sys.py3kwarning
sys.__doc__ sys.__stdout__ sys.exc_info( sys.getsizeof( sys.setcheckinterval(
sys.__excepthook__( sys.__str__( sys.exc_type sys.gettrace( sys.setdlopenflags(
sys.__format__( sys.__subclasshook__( sys.excepthook( sys.hexversion sys.setprofile(
sys.__getattribute__( sys._clear_type_cache( sys.exec_prefix sys.maxint sys.setrecursionlimit(
sys.__hash__( sys._current_frames( sys.executable sys.maxsize sys.settrace(
sys.__init__( sys._getframe( sys.exit( sys.maxunicode sys.stderr
sys.__name__ sys.api_version sys.exitfunc( sys.meta_path sys.stdin
sys.__new__( sys.argv sys.flags sys.modules sys.stdout
sys.__package__ sys.builtin_module_names sys.float_info sys.path sys.subversion
sys.__reduce__( sys.byteorder sys.getcheckinterval( sys.path_hooks sys.version
sys.__reduce_ex__( sys.call_tracing( sys.getdefaultencoding( sys.path_importer_cache sys.version_info
sys.__repr__( sys.callstats( sys.getdlopenflags( sys.platform sys.warnoptions
>>> sys.
然后可以在.bashrc里面加一个环境配置,
export PYTHONSTARTUP=/usr/lib64/python2.6/tab.py
执行命令source .bashrc
然后就可以不用在引用就直接可以TAB啦
转载于:https://blog.51cto.com/duwers/1958076