Python 官方文档:入门教程 => 点击学习
有时候用python处理一些简单的事务,为此打开编辑器编辑一个可执行的py文件保存执行就显得得不偿失了。这时,可以定制一下Python提供的交互式命令行来实现Tab补全和历史命令补全。当然,你也可以简单的安装ipython实现上述功
有时候用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命令行
--结束END--
本文标题: python定制交互式命令行
本文链接: https://www.lsjlt.com/news/186682.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0