Windows 版 Python 上存储的控制台输入历史记录在哪里? [英] Where is console input history stored on Python for Windows?

查看:101
本文介绍了Windows 版 Python 上存储的控制台输入历史记录在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好,

问题

对于 Windows 版本的 Python,是否存在存储条目的特定位置,或者它只是一组本地存储变量?

Is there a particular spot that the entries are stored, or is it just a local set of stored variables, for the windows version of Python?

背景

我很好奇 Python.exe 在哪里存储从命令行输入的条目,不是 Tkinter GUI.我对此特别感兴趣,因为我注意到如果您在 raw_input() 中输入,您可以求助于以前的条目.已经有很多关于 raw_input()input() 接收某种可编辑的默认参数的讨论.

I am curious about where Python.exe stores the entries typed out from the command line, not the Tkinter GUI. I'm particularly interested in this because I've noticed you can resort to previous entries if you are typing in raw_input(). There have been many discussions in regards to raw_input() and input() receiving some sort of default argument that is editable.

看.此链接指向相关的 SO 问题

显然,这对于带有模块的 Linux/GNU 非常可行,这些模块将允许您利用 Bash 的格式.Windows 用户在这方面并不走运.

Obviously this is very doable with Linux / GNU with modules that will allow you to take advantage of Bash's format. Windows users are unlucky in that regard.

关于这些模块的说明:

readline 基于 GNU,无法在 Windows 中正常工作.

readline is GNU based and does not work properly in Windows.

pyreadline 对命令行解释器没有好处.

pyreadline does not benefit the command line interpreter.

curses 是基于 GNU 的,在 Windows 中根本不起作用.

curses is GNU based and does not work at all in Windows.

跟进

我得出的结论是,如果给用户一组预定义的条目,您可以限制输入到命令空间的内容.

The conclusion I'm arriving to is that if the user is given a pre-defined set of entries, you can limit what is entered into the command space.

附言- 我知道创建一个基于 PySide、Tkinter 或其他"的 GUI 来解决我的问题要容易得多.

P.S. - I understand it is much easier to just create a PySide, Tkinter or "other"-based GUIs to get around what I'm asking.

詹姆斯爵士

推荐答案

在 Windows 7 上,使用标准 Python 3.7 命令解释器(不是 IPython 或 IDLE),命令历史记录存储在文件 %USERPROFILE%\.python_history.此位置不用于 Python 2.7.x,因为 Python 命令历史记录功能是从 Python 3.4 开始引入的.

On Windows 7, using the standard Python 3.7 command interpreter (not IPython or IDLE), the command history is stored in the file %USERPROFILE%\.python_history. This location is not used for Python 2.7.x, as the Python command history feature was introduced starting with Python 3.4.

这篇关于Windows 版 Python 上存储的控制台输入历史记录在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆