为Python添加交互模式下TAB自动补全以及命令历史功能。

1.获取python目录

[root@localhost ~]# python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python2.6/site-packages/paramiko-1.7.7.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/lib64/python2.6/site-packages/gst-0.10', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib64/python2.6/site-packages/webkit-1.0', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info']
>>>

从上面看出python在我系统上的路径是  /usr/lib/python2.6/site-packages

2.切换至该目录写个tab.py的脚本,脚本目录就是处理python中<tab>事件,脚本内容如下

[root@localhost]# cd /usr/lib/python2.6/site-packages

[root@localhost python2.6/]# vim 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

3.切换至自己主目录

[root@localhost python2.6]# cd
[root@localhost ~]# vim .bashrc

4. 增加环境变量

export PYTHONSTARTUP=/usr/lib/python2.6/site-packages/tab.py  

5.配置环境变量生效

[root@localhost ~]# source .bashrc

  

  

  

  

最新文章

  1. css3 动画的有关属性
  2. 什么是XMLA-- XML for Analysis
  3. java多线程synchronized底层实现
  4. web.xml中配置log4j
  5. CTreeCtrl 控件使用总结
  6. windows 系统下C++实现的多线程
  7. shadow dom 隔离代码 封装
  8. tomcat中Servlet的工作机制
  9. MySQL和B树的那些事
  10. React使用Styled-Componets来添加样式
  11. MyCat原理及分布式分库分表
  12. CF438E The Child and Binary Tree(生成函数,NTT)
  13. 离开(切换)当前页面时改变页面title
  14. Python3基础 list + *运算 扩充列表
  15. 关于ES6的一些新特性的学习
  16. netty的decoder encoder
  17. TZOJ 2754 Watering Hole(最小生成树Kruskal)
  18. Ubuntu 忘记密码后重置密码
  19. 利用DNS进行传输数据
  20. WebForm 使用点滴。。。。

热门文章

  1. javac 编译与 JIT 编译
  2. thinkphp框架中“关联操作”的完整定义详解
  3. MySQ中Lmax_connections的合理设置
  4. for循环 打印菱形 空 和 实
  5. 【BZOJ-1976】能量魔方Cube 最小割 + 黑白染色
  6. 【BZOJ-1009】GT考试 KMP+DP+矩阵乘法+快速幂
  7. kali2016.2源
  8. springMVC-InitBinder
  9. 数据结构算法C语言实现(二十七)--- 7.2图的遍历
  10. [iOS 利用MapKit和CoreLocation框架打造精简的定位和导航]