Python的tab自动补全脚本

1.首先用vim打开一个文件,然后加入以下代码

[cc lang="bash"]
[root@kali py]# vim tab.py
[/cc]

[cc lang="bash"]
#!/usr/bin/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
[/cc]

2.打开python并导入模块即可使用自动补全。

[cc lang="bash"]
[root@kali py]# python
[/cc]

Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tab //导入tab
>>> import sys
>>> sys. 按tab即可补全…
python2015061201


发表评论

登录 后发表评论.