配置python tab键自动补全

我的系统以及python环境(centos6默认python):

# cat /etc/redhat-release 
CentOS release 6.7 (Final)

# python -V
Python 2.6.6

# rpm -qa | grep python
python-setuptools-0.6.10-3.el6.noarch
python-2.6.6-64.el6.x86_64
python-pycurl-7.19.0-8.el6.x86_64
python-iniparse-0.3.1-2.1.el6.noarch
python-pip-1.3.1-4.el6.noarch
python-libs-2.6.6-64.el6.x86_64
python-urlgrabber-3.9.1-9.el6.noarch
rpm-python-4.8.0-47.el6.x86_64
newt-python-0.52.11-3.el6.x86_64
# mkdir /usr/lib/python2.6/lib-dynload
# cp /usr/lib64/python2.6/lib-dynload/readline.so /usr/lib/python2.6/lib-dynload

# python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
>>> 

然后在/usr/lib/python2.6/site-packages/ 添加一个tab.py文件即可使用import tab

# vim /usr/lib/python2.6/site-packages/tab.py
try:
    import readline
except ImportError:
    print("Module readline not available.")
else:
    import rlcompleter
    readline.parse_and_bind("tab: complete")

试一下有没有生效

# python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
>>> import tab
>>> he
help(  hex(   
>>> help(
Display all 175 possibilities? (y or n)
ArithmeticError(            all(                        intern(
AssertionError(             and                         is

你可能感兴趣的:(python学习笔记)