注:此文为转载他人博客,如有侵权,请联系我删除
1.我们需要一个tab补全的功能脚本
#!/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存放路径
我的默认路径为:/usr/lib/python2.7 (可通过sys.path查找)
3.在默认存放路径下新建一个文件存放1中的代码
test@test:~$ sudo vim /usr/lib/python2.7/tab.py (在根目录下不用sudo)
4.在导入sys模块后,直接调用tab即可