python的tab自动补全

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python的tab自动补全相关的知识,希望对你有一定的参考价值。

 

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

 

代码有了,我们还需要将脚本放到python指定的目录下,可以使用sys.path来查看一下

>>> import sys
>>> sys.path
[‘‘, /usr/lib/python2.7, /usr/lib/python2.7/plat-x86_64-linux-gnu, /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, /usr/lib/python2.7/dist-packages/PILcompat, /usr/lib/python2.7/dist-packages/gtk-2.0, /usr/lib/python2.7/dist-packages/ubuntu-sso-client]
  一般我们会将这一类代码放在/usr/local/lib/python2.7/dist-packages目录下

 

mv tab.py /usr/lib64/python2.7/site-packages/

 

以上是关于python的tab自动补全的主要内容,如果未能解决你的问题,请参考以下文章

设置python中TAB键自动补全方法

Python基础 (tab自动补全)

python tab 自动补全

python的tab自动补全

Python建立Tab自动补全的脚本

Python Tab自动补全