python script to pickle entire environment

pickle, python

Solution

I think you want Dill:

In addition to pickling python objects, dill provides the ability to save the state of an interpreter session in a single command. Hence, it would be feasable to save a interpreter session, close the interpreter, ship the pickled file to another computer, open a new interpreter, unpickle the session and thus continue from the 'saved' state of the original interpreter session.

Note that it's still in alpha, so don't rely on it to store critical data.

Of course, some things can't be restored, such as an open file handle. But you can get quite close.

Problem

I'm working inside the Python REPL, and I want to save my work periodically. Does anybody have a script to dump all the variables I have defined? I'm looking for something like this: ``` for o in dir(): f=open(o) pickle(o_as_object, f) ``` This seems like something other people have done, so I wanted to ask before re-inventing the wheel.

Original source