玩转Linux的朋友们,还在为python默认的无tab补全而烦恼吗?
下面是在下的一个解决方法,希望能帮助到新入学python的学者。
第一步:编写一键补全脚本tab.py
[[email protected]~]#vim tab.py
#!/usr/bin/env python
import sys
import readline
import rlcompleter
import atexit
import os
#tab completion
readline.parse_and_bind(‘tab: complete‘)
第二步:进入python交互模式,查看python模块导入的选择顺序
[[email protected] ~]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
[‘‘, ‘/usr/lib64/python27.zip‘, ‘/usr/lib64/python2.7‘, ‘/usr/lib64/python2.7/plat-linux2‘, ‘/usr/lib64/python2.7/lib-tk‘, ‘/usr/lib64/python2.7/lib-old‘, ‘/usr/lib64/python2.7/lib-dynload‘, ‘/usr/lib64/python2.7/site-packages‘, ‘/usr/lib64/python2.7/site-packages/gtk-2.0‘, ‘/usr/lib/python2.7/site-packages‘]
>>>
第三步:拷贝一键补全脚本到python模块默认路径/usr/lib64/python2.7
[[email protected] ~]cp tab.py /usr/lib64/python2.7/
第四步:导入一键补全模块
[[email protected] ~]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tab
>>> import sys
>>> sys. ——双tab
sys.__class__( sys.exitfunc(
sys.__delattr__( sys.flags
...