栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

给Python终端一个持久的历史

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

给Python终端一个持久的历史

当然可以,只需一个小的启动脚本。从交互式输入编辑及历史替换在Python教程:

# Add auto-completion and a stored history file of commands to your Python# interactive interpreter. Requires Python 2.0+, readline. Autocomplete is# bound to the Esc key by default (you can change it - see readline docs).## Store the file in ~/.pystartup, and set an environment variable to point# to it:  "export PYTHonSTARTUP=~/.pystartup" in bash.import atexitimport osimport readlineimport rlcompleterhistoryPath = os.path.expanduser("~/.pyhistory")def save_history(historyPath=historyPath):    import readline    readline.write_history_file(historyPath)if os.path.exists(historyPath):    readline.read_history_file(historyPath)atexit.register(save_history)del os, atexit, readline, rlcompleter, save_history, historyPath

从Python
3.4开始,交互式解释器开箱即用地支持自动完成和历史记录:

现在,在支持的系统上的交互式解释器中,默认情况下启用了制表符完成功能

readline
。默认情况下,历史记录也处于启用状态,并且被写入文件(或从文件中读取)
~/.python-history



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/405645.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号