发布时间:2019-08-28 09:06:24编辑:auto阅读(2446)
有时候用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
53728
40565
34988
30710
25578
25353
23792
19262
15387
14881
1426°
1319°
1418°
1448°
1463°
1645°
1593°
1507°
1604°
1560°