Save Python Interactive Session to a File

It can be helpful to save the contents of a python interpreter interactive session for review; do so by executing the following commands at the end of your interactive session:

import readline
readline.write_history_file('/home/barack/history')

This produces a file at the specified path containing the entirety of the interactive session; made possible by the readline module's write_history_file method:

Save the history list to a readline history file, overwriting any existing file. The default filename is ~/.history. This calls write_history() in the underlying library.

Tags

 Python