让python的交互解释器支持tab补全、提示功能
方法1:
一、执行python脚本
1.创建一个python脚本,以.py结尾:
脚本如下:
import sys
import readline
import rlcompleter
import atexit
import os
readline.parse_and_bind(‘tab:complete‘)
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
2.查看python的运行环境
[root@localhost ~]# whereis python
python: /usr/bin/python /usr/bin/python2.6/usr/lib/python2.6 /usr/lib64/python2.6 /usr/include/python2.6/usr/share/man/man1/python.1.gz
3.给tab.py设置权限,并把tab.py复制到相应的目录
chmod 755 tab.py
cp tab.py /usr/lib64/python2.6/site-packages/
至此,python的补全功能已经完成。
例子:
# python
>>> import tab
>>> pri<tab>
>>> import sys
>>> sys.<tab><tab>
方法2:
安装ipython:提供补全功能
[root@localhost ~]#tar xf ipython-1.2.0.tar.gz
cd ipython-1.2.0
[root@localhostipython-1.2.0]# /usr/local/python27/bin/python2.7 setup.py build
[root@localhostipython-1.2.0]# /usr/local/python27/bin/python2.7 setup.py install
[root@localhostipython-1.2.0]# ln -sv /usr/local/python27/bin/python2.7 /usr/bin/python2.7
[root@localhostipython-1.2.0]# ln -sv /usr/local/python27/bin/ipython /usr/bin/
[root@localhostipython-1.2.0]# ipython
本文出自 “蛋鱼水” 博客,请务必保留此出处http://zhongguiyao.blog.51cto.com/11712990/1854963
原文地址:http://zhongguiyao.blog.51cto.com/11712990/1854963