簡體   English   中英

從 Windows 上的交互式提示打印 Python 歷史記錄

[英]Print Python history from interactive prompt on Windows

我正在 Windows 10 上使用默認的 python 解釋器,我可以使用箭頭鍵一一通過它們 go。 但是有沒有像 bash shell 中的history命令這樣的選項,它顯示了你迄今為止輸入的所有命令?

這是您如何查看交互式 Python 中的整個命令歷史記錄的近乎副本? ,除了它是針對 Windows 10而不是 macos/*nix 的。 那里的解決方案要么推薦我不經常使用的 iPython,要么使用 Windows 上沒有的 readline。

我已經安裝了 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.
>>>

總結一下 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.

如果您安裝pyreadline ,則可以import readline並使用此答案中描述的技術。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM