设置python中TAB键自动补全方法python
linux服务器上:###########################################################################linux
1、建立自动补全脚本以下:shell
vi /tmp/python/tab.pywindows
#!/usr/bin/python服务器
# python tab file app
import syside
import readlinespa
import rlcompleterorm
import atexitip
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
2、导入上面建立的模块
-----------------方法一:
#python
>>>import sys
>>>sys.path.append('/tmp/python/')
>>>import tab
----------------方法二:
cp /tmp/python/tab.py /usr/lib/python2.6/site-packages
#python
>>>import tab
#至此即可利用TAB补全了
#########################################################################
ipython也有tab自动补全功能,安装方法以下:
tar -zxvf ipython-0.12.tar.gz
cd ipython-0.12
python setup.py install
ipython
#注:在ipython中使用!加命令九如同在shell中同样,如!init 0
windows服务器上:###########################################################################
一、安装Python后将C:\Python27和C:\Python27\Scripts加入系统环境变量path中
二、安装pyreadline,方法以下:
pip.exe install pyreadline 或者easy_install pyreadline
三、在C:\Python27\Lib\site-packages新建tab.py,内容以下
#!/usr/bin/python
# python tab 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['HOMEPATH'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter
####################################################################
在一个系统中共存Python二、python3的时候,pip、pip二、pip3使用的时候会报错:
c:\Python36\Scripts>pip3
Fatal error in launcher: Unable to create process using '"'
解决方法:
python3:
python3 -m pip install --upgrade pip
python2:
python2 -m pip install --upgrade pip
注意:python2, python3共存时,将python安装目录下的python.exe改为对应的python2.exe,python3.exe
python3 -m pip pyreadline 或者python3 -m easy_install pyreadline