发布时间:2019-08-28 09:06:24编辑:auto阅读(2016)
有时候用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
51315
50764
41361
38168
32648
29539
28384
23258
23228
21553
1627°
2362°
1964°
1909°
2238°
1946°
2638°
4423°
4264°
3034°