用Python时没有tab补全还是挺痛苦的,记录一下添加该功能的方法利人利己
1. 先准备一个tab.py的脚本
shell> cat tab.py
#!/usr/bin/python
# python tab 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默认的模块存放地址
>>> import tab
>>> import sys
>>> sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-arm-linux-gnueabihf', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']
3. 拷贝该脚本到默认模块存放路径
cp tab.py /usr/lib/python2.7
4. 现在可以用了
>>> import sys
>>> sys.
sys.__class__( sys.builtin_module_names sys.last_value
sys.__delattr__( sys.byteorder sys.long_info
sys.__dict__ sys.call_tracing( sys.maxint
sys.__displayhook__( sys.callstats( sys.maxsize
sys.__doc__ sys.copyright sys.maxunicode
sys.__excepthook__( sys.displayhook( sys.meta_path
sys.__format__( sys.dont_write_bytecode sys.modules
sys.__getattribute__( sys.exc_clear( sys.path
sys.__hash__( sys.exc_info( sys.path_hooks
sys.__init__( sys.exc_type sys.path_importer_cache
sys.__name__ sys.excepthook( sys.platform