Tag Archives: python shell

How to get list of all commands run in python shell?

We most often use python interactive shell to input commands, instead of writing them as full fledged script file. This is handy and gives us a check on what libraries to import, where a possible error can occur and rectify any problem per line of code.

With Jupyter notebooks, we are able to work around very easily. But, in a traditional environment, how to get back a copy of all commands that were typed into python interactive shell?

We use readline to do this job.

import readline


The above code will store the entire command history into a text file by name python_history in the current working directory.

I always take backup of commands input and check it back in order to have a glimpse of what worked and what not.

Readline also allows us to clear the command input history :



to clear/flush the command history.


Leave a comment

Filed under geek