Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19k points)

I find myself frequently using Python's interpreter to work with databases, files, etc -- basically a lot of manual formatting of semi-structured data. I don't properly save and clean up the useful bits as often as I would like. Is there a way to save my input into the shell (db connections, variable assignments, little for loops and bits of logic) -- some history of the interactive session? If I use something like script I get too much stdout noise. I don't really need to pickle all the objects -- though if there is a solution that does that, it would be OK. Ideally, I would just be left with a script that ran as the one I created interactively, and I could just delete the bits I didn't need. Is there a package that does this, or a DIY approach?

1 Answer

0 votes
by (106k points)

If you like to use the interactive session than IPython is extremely useful. There is a %save command for your use-case, you only need to input like as follows %save my_useful_session.

Another thing you can do is use the readline module below is a code example that shows the use of readline module:-

import readline

readline.write_history_file('/home/ahj/history')

Related questions

0 votes
1 answer
0 votes
4 answers
0 votes
1 answer
0 votes
1 answer
asked Sep 10, 2019 in Python by Sammy (47.6k points)

Browse Categories

...