大家在刚使用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 ~/.bashrc
export PYTHONSTARTUP=/usr/lib64/python2.6/startup.py
4. 重启系统就可以了