Print Python history from interactive prompt on Windows

Viewed 879

I'm working on the default python interpreter on Windows 10, and I can go through them one by one using the arrow keys. But is there an option like the history command in bash shell, which shows you all the commands you've entered so far?

This is a near duplicate of How do you see the entire command history in interactive Python?, except that it is for Windows 10 instead of macos/*nix. The solutions over there either recommend iPython, which I'm not often using, or use readline, which is not available on Windows.

I have installed the pyreadline package, but it doesn't seem to be a drop-in replacement in this case.

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.
>>>
1 Answers

To summarize what ErykSun and Vova said in the comments on the question:

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.

Related