Python tab键补全
python装完是不能用tab来补全的,我们需要将脚本放到Python指定的目录下,可以使用sys.path来查看一下目录
>>> import sys
>>> sys.path
['', '/usr/local/python2.7.10/lib/python27.zip', '/usr/local/python2.7.10/lib/python2.7', '/usr/local/python2.7.10/lib/python2.7/plat-linux2', '/usr/local/python2.7.10/lib/python2.7/lib-tk', '/usr/local/python2.7.10/lib/python2.7/lib-old', '/usr/local/python2.7.10/lib/python2.7/lib-dynload', '/usr/local/python2.7.10/lib/python2.7/site-packages']
一般我们会将这一类代码放在/usr/local/xxxxx/lib/python2.7/dist-packages目录下
[root@python ~]# cd /usr/local/python2.7.10/lib/python2.7/site-packages
[root@python site-packages]# vi 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
[root@python site-packages]# python
Python 2.7.10 (default, Dec 4 2015, 23:46:26)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more infORMation.
>>> import tab
>>> import sys
>>> sys.
sys.__class__( sys.__reduce_ex__( sys.argv sys.exit( sys.hexversion sys.py3kwarning
sys.__delattr__( sys.__repr__( sys.builtin_module_names sys.exitfunc( sys.long_info sys.setcheckinterval(
sys.__dict__ sys.__setattr__( sys.byteorder sys.flags sys.maxint sys.setdlopenflags(
sys.__displayhook__( sys.__sizeof__( sys.call_tracing( sys.float_info sys.maxsize sys.setprofile(
相关文章