python之 自動補全 tab

張衝andy發表於2018-12-29

1、在python中執行命令sys.path檢視python路徑

>>> import sys
>>> import tab
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named tab


>>> sys.path
['', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/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/lib64/python2.6/site-packages/gst-0.10', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib64/python2.6/site-packages/webkit-1.0', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info']


2、建立 tab.py 檔案
[root@mysql2 ~]# cd /usr/lib/python2.6/site-packages

[root@mysql2 site-packages]# 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


3、 匯入 tab 模組
>>> import tab
>>> f
file( filter( finally float( for format( from frozenset(


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31383567/viewspace-2286980/,如需轉載,請註明出處,否則將追究法律責任。

相關文章