Python history
Are you aware that there's a Python history file? It's similar to the various history files on *nix systems such as zsh_history and bash_history.
Location
Location
The python_history file is a hidden file in your home directory on macOS (Darwin) and *nix systems.
/Users/<username>/.python_history
What and when does it record?
What and when does it record?
When you open a Python interpreter from your command shell - the text you type into the interpreter will be prepared to be recorded.
It will only write to the file if you cleanly close the Python interpreter session using the exit function.
exit()
If you kill the Python interpreter session with something like Ctrl + Z - the session is not saved to the file.