python学习笔记--导入tab键自动补全功能的配置

今天开始学习Python,必须配置tab键补全功能

1.首先我们需要查看python的安装路径

[root@abc ~]# python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python2.6/site-packages/cloud_init-0.7.6-py2.6.egg', '/usr/lib/python2.6/site-packages/jsonpatch-1.13-py2.6.egg', '/usr/lib/python2.6/site-packages/requests-2.9.1-py2.6.egg', '/usr/lib/python2.6/site-packages/argparse-1.4.0-py2.6.egg', '/usr/lib/python2.6/site-packages/Jinja2-2.8-py2.6.egg', '/usr/lib/python2.6/site-packages/jsonpointer-1.10-py2.6.egg', '/usr/lib/python2.6/site-packages/six-1.10.0-py2.6.egg', '/usr/lib/python2.6/site-packages/AliyunUtil-0.0.1-py2.6.egg', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info']

 


2.切换目录到python的安装目录下,进行tab键补全模块的编写

 
 
[root@localhost ~]# cd /usr/lib64/python2.6
[root@localhost python2.6]# vim tab.py

#!/usr/bin/env python
# python startup 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

 注意:一定要安装上边代码的严格缩进来做,防止不生效。

进入家目录,编写 .bashrc文件在最后添加下面一行,保存退出。

[root@localhost ~]# cd ~

[root@localhost ~]# vim .bashrc

export PYTHONSTARTUP=/usr/lib64/python2.6/tab.py

 

家目录.bashrc文件只有用户登录时才会加载生效,需要进行下面的操作来生效

[root@localhost ~]# source .bashrc

 

那么现在就可以使用tab键补全功能了



转载于:https://www.cnblogs.com/taiguyiba/p/6039331.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值