您的位置:首页 > 运维架构 > Linux

如何在Linux python中使用tab补全

2016-03-20 10:06 585 查看
大家在刚使用Linux过程中接触python的话是不能用tab补全的,这让初学者很困惑,所以我在网上整理了一下过程简单来给大家讲解。
1. 查看python安装路径:
>>> import sys
>>> sys.path
['', '/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']
2. 进入python目录下写一个小脚本:
[root@python python2.6]# vim startup.py#!/usr/bin/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 3. 最后再设置开机自动导入脚本:
[root@python python2.6]# cat ~/.bashrcexport PYTHONSTARTUP=/usr/lib64/python2.6/startup.py 4. 重启系统就可以了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python Linux tab