1、編寫一個tab的自動補全腳本,名為tab.py
#!/usr/bin/python # python tab complete 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中查看python的模塊路徑信息
>>> import sys >>> sys.path ['', '/usr/lib/python26.zip', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/gst-0.10', '/usr/lib/python2.6/site-packages/gtk-2.0', '/usr/lib/python2.6/site-packages/webkit-1.0'] >>>
python的模塊放在了/usr/lib/python26下面,將腳本拷貝到該目錄下,在使用時導入即可。
3、導入tab
>>> import tab >>> os. Display all 244 possibilities? (y or n)
4、但python讀取模塊的路徑順序優先是從當前目錄開始,所以若是當前目錄也存在tab.py,但內容不同的python腳本,則可能會報錯,所以在環境變量中也指定tab.py腳本
#for python export PYTHONSTARTUP=/usr/lib/python2.6/tab.py