Many times I will use the Python interpreter to inspect variables and step through commands before I actually write to a file. However by the end I have around 30 commands in the interpreter, and have to copy/paste them into a file to run. Is there a way I can export/write the Python interpreter history into a file?
For example
>>> a = 5
>>> b = a + 6
>>> import sys
>>> export('history', 'interactions.py')
And then I can open the interactions.py file and read:
a = 5
b = a + 6
import sys
IPython is extremely useful if you like using interactive sessions. For example for your usecase there is the save command, you just input save my_useful_session 10-20 23 to save input lines 10 to 20 and 23 to my_useful_session.py. (to help with this, every line is prefixed by its number)
Look at the videos on the documentation page to get a quick overview of the features.
::OR::
There is a way to do it. Store the file in ~/.pystartup
You can also add this to get autocomplete for free:
Please note that this will only work on *nix systems. As readline is only available in Unix platform.