python补全用法,windows环境和linux环境
一、windows中python tab具体如下:
1.python3环境装好后,初始环境是没有装readline模块的,先装它。
pip install pyreadline
2.在在python的根目录下加上tab模块脚本,如下:
#!/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
后面就可以用了:
#####################################################################################
二、linux 中python tab具体如下:
1.先安装python,随便先下个3版本
wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tar.xz
xz -d Python-3.6.7.tar.xz
tar -xf Python-3.6.7.tar
2.装一些环境包,顺便装下readline
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
3.编译安装
cd /opt/Python-3.6.7
./configure --prefix=/opt/python
make && make install
4.添加环境变量
将export PATH=$PATH:/opt/python/bin 添加到/etc/profile,再sour'ce下
5.再cd /opt/python/lib/python3.6 添加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[ 'HOME' ], '.pythonhistory' )
try :
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter
6.搞定,试下结果
可以补全了。