Python基础 (tab自动补全)

Python 自动补全

1、添加python自动补全的脚本

vim ~/.pythonstartup     #添加如下
#!/usr/bin/python
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

2、添加到~/.bashrc

echo ‘export PYTHONSTARTUP="/root/.pythonstartup"‘  >> ~/.bashrc
source ~/.bashrc                      

3、测试

[[email protected] ~]# python
Python 2.7.11 (default, Mar 29 2016, 23:35:44)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.t                            #tab可以补全
os.tcgetpgrp(  os.tcsetpgrp(  os.tempnam(    os.times(      os.tmpfile(    os.tmpnam(     os.ttyname(
时间: 2024-08-06 07:34:22

Python基础 (tab自动补全)的相关文章

python的tab自动补全

很久不写blog了. 最近发现python的自动补全是个好东西. 分享一下. 参考了:http://www.cnblogs.com/allenblogs/archive/2011/04/21/2023288.html 和 软件手册 下载地址:http://vim.sourceforge.net/scripts/script.php?script_id=850 直接粘贴了. ------------------------------ vim编辑器中 #mkdir -p ~/.vim/after/

Python添加tab自动补全及命令历史功能。

1. 新建Python环境变量配置文件: vim ~/.pystartup # Add auto-completion and a stored history file of commands to your Python # interactive interpreter. Requires Python 2.0+, readline. Autocomplete is # bound to the Esc key by default (you can change it - see rea

为python添加tab自动补全功能

fedora ~ $ python Python 2.7.8 (default, Nov 10 2014, 08:19:18) [GCC 4.9.2 20141101 (Red Hat 4.9.2-1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys        

Python建立Tab自动补全的脚本

1 #!/usr/bin/python 2 #python steup file 3 import sys 4 import readline 5 import rlcompleter 6 import atexit 7 import os 8 # tab completion 9 readline.parse_and_bind('tab: complete') 10 #history file 11 histfile = os.path.join(os.environ['HOME'], '.p

python交互模式下的tab自动补全

python在交互模式下,输入命令的时候按tab键就按时间tab键的功能输出,在书写python时多有不便. 把下面的代码写入一个文件tab.py,放到/usr/lib/python2.6/site-packages/下 #!/usr/bin/env python import sys import readline import rlcompleter import atexit import os readline.parse_and_bind('tab:complete') histfil

python2.7 tab,自动补全

python <tab>自动补全 一.这个方法可以修改shell命令行的自动补全 1.获取python目录[我使用的是64位ubuntu系统] [~$]python Python 2.7.3 (default, Apr 10 2013, 06:20:15) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more 

CentOs6.5 更新python2.7,以及tab自动补全

#安装python2.7之前,准备工作: yum install python-devel gcc patch readline* -y #解压并安装: tar xf Python-2.7.10.tar.xz cd Python-2.7.10 sed -i 's/#readline/readline/g' Modules/Setup.dist ./configure --prefix=/usr/local/python make && make install #更改系统python调用

windows下Python shell代码自动补全

Unix下实现如题功能用下面的代码: import rlcompleter, readline readline.parse_and_bind('tab: complete') 但readline不能在win中用,需要为windows编译好的pyreadline pip install pyreadline import rlcompleter, pyreadline a=Readline() a.parse_and_bind('tab: complete') windows下Python sh

sudo和man的tab自动补全

要加入sudo和man的tab自动补全功能,只需在~/.bashrc中加入: #Enabling tab-completioncomplete -cf sudocomplete -cf man