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.

2
  • 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. Commented Mar 13, 2012 at 17:36
  • do you mean shelve stackoverflow.com/questions/2960864/… Commented Jan 29, 2015 at 18:44

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

This works for Python Shell.

4 Comments

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.
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 ...
did u save ur file with .py extension. "filename.py" is mandatory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.