1

Is there a way to save the current Python session? I would like to be able to save all my Python variables, functions, and imported libraries. If possible, having the history saved would be nice. I have looked all over Google and Stackoverflow for a simple command to do this, but have found nothing quite fitting what I want. Some suggested downloading new software, which I don't want. Others had big scripts that they wrote to do this for them.

I'm looking for a no-nonsense easy to use command. Is there one? If not, how would you suggest to make one?

UPDATE: readline.write_history_file() and readline.read_history_file() save the history.

CoffeeRain
  • 4,460
  • 4
  • 31
  • 50
  • 3
    There's no reliable way to save a whole session, since it can contain ressources like sockets and open files. I'd recommend to use an interactive interpreter that supports logging and replaying sessions, like IPython. This would of course mean you'd need to install IPython, but I can't see any reason why you shouldn't. – Sven Marnach Mar 13 '12 at 17:36
  • do you mean shelve http://stackoverflow.com/questions/2960864/how-can-i-save-all-the-variables-in-the-current-python-session – rwnew2012 Jan 29 '15 at 18:44

2 Answers2

3

I think the closest thing you're going to find is ipython. I'm not sure if it does the variable saving thing, but I believe it does everything else you're asking for.

Ethan Furman
  • 63,992
  • 20
  • 159
  • 237
0

1.) After typing all commands just do CTRL+S. 2) Give a file name and say OK.

This works for Python Shell.

Teja
  • 13,214
  • 36
  • 93
  • 155
  • That's close to what I want, but not quite. I wanted to be able to load the session back in instead of just being able to see it. – CoffeeRain Mar 13 '12 at 17:36
  • Go to File and click on open... It will pop up one browsing window for u.. then select the file name u saved with before ... – Teja Mar 13 '12 at 17:38
  • did u save ur file with .py extension. "filename.py" is mandatory – Teja Mar 13 '12 at 17:41
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/8832/discussion-between-coffeerain-and-venk) – CoffeeRain Mar 13 '12 at 17:45