发布时间:2019-08-28 09:06:24编辑:auto阅读(1824)
有时候用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
49146
48293
39019
36140
30551
27348
26351
21179
21022
19360
139°
144°
240°
430°
287°
956°
984°
971°
973°
933°