您的位置:首页 > 编程语言 > Python开发

Python命令行自动补全和记录历史命令

2013-07-21 15:21 666 查看
[root@mm_local ~]# echo "export PYTHONSTARTUP='/root/.pythonstartup'" >> /root/.bashrc
[root@mm_local ~]# source /root/.bashrc
[root@mm_local ~]# cat /root/.pythonstartup
import os
import readline
import rlcompleter
import atexit

#tab completion
readline.parse_and_bind("tab: complete")

#history file
history_file = os.path.join(os.environ["HOME"],".pythonhistory")
try:
readline.read_history_file(history_file)
except IOError:
pass
atexit.register(readline.write_history_file,history_file)

del os,history_file,readline,rlcompleter
[root@mm_local ~]# python
Python 2.7.3 (default, Jun  5 2013, 22:40:26)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path<tab> #按tab键就可以自动补全了

[root@mm_local ~]# python
>>>
>>> sys.path #按上下方向键即可找到历史命令
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: