发布时间:2019-08-28 09:06:24编辑:auto阅读(2026)
有时候用python处理一些简单的事务,为此打开编辑器编辑一个可执行的py文件保存执行就显得得不偿失了。这时,可以定制一下python提供的交互式命令行来实现Tab补全和历史命令补全。当然,你也可以简单的安装ipython实现上述功能。
实现方法:
1.在家目录下编辑.pythonstartup,内容如下(可能需要安装python的readline模块)
# python startup
import readline
import rlcompleter
import atexit
import os
# tab compltion
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 2.在.bash_profile文件添加如下行
export PYTHONSTARTUP=~/.pythonstartup
3.重读.bash_profile
. .bash_profile
好了,现在你就有了一个功能增强的py命令行
上一篇: python特殊函数之lambda和ma
下一篇: python模块介绍- socket(1
51372
50844
41432
38228
32724
29622
28439
23345
23287
21617
1705°
2433°
2032°
1969°
2315°
1997°
2708°
4533°
4348°
3100°