简体   繁体   English

从 Windows 上的交互式提示打印 Python 历史记录

[英]Print Python history from interactive prompt on Windows

I'm working on the default python interpreter on Windows 10, and I can go through them one by one using the arrow keys.我正在 Windows 10 上使用默认的 python 解释器,我可以使用箭头键一一通过它们 go。 But is there an option like the history command in bash shell, which shows you all the commands you've entered so far?但是有没有像 bash shell 中的history命令这样的选项,它显示了你迄今为止输入的所有命令?

This is a near duplicate of How do you see the entire command history in interactive Python?这是您如何查看交互式 Python 中的整个命令历史记录的近乎副本? , except that it is for Windows 10 instead of macos/*nix. ,除了它是针对 Windows 10而不是 macos/*nix 的。 The solutions over there either recommend iPython, which I'm not often using, or use readline, which is not available on Windows.那里的解决方案要么推荐我不经常使用的 iPython,要么使用 Windows 上没有的 readline。

I have installed the pyreadline package , but it doesn't seem to be a drop-in replacement in this case. 我已经安装了 pyreadline package ,但在这种情况下它似乎不是一个替代品。

C:\Users\yoder>python
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

To summarize what ErykSun and Vova said in the comments on the question:总结一下 ErykSun 和 Vova 在对该问题的评论中所说的话:

If you are running Python within a cmd prompt and have not installed pyreadline , you can press F7 to bring up cmd 's native history, which Python uses for its own history. If you are running Python within a cmd prompt and have not installed pyreadline , you can press F7 to bring up cmd 's native history, which Python uses for its own history.

If you have installed pyreadline , then you can import readline and use the techniques described in this answer .如果您安装pyreadline ,则可以import readline并使用此答案中描述的技术。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM