Pickling a dictionary

Peter Otten __peter__ at web.de
Wed Nov 7 17:26:23 CET 2012

Devashish Tyagi wrote:

> So I want to store the current state of a InteractiveInterpreter Object in
> database. In order to achieve this I tried this
> obj = InteractiveInterpreter()
> local = obj.locals()
> pickle.dump(local, open('obj.dump','rw'))

Assuming InteractiveInterpreter is imported from the code module the above 
will fail with a TypeError. Please copy-and paste code snippets to avoid 
guessing games.

> But I received an error say
> TypeError: can't pickle ellipsis objects
> From what I understand this shouldn't occur as local is a dictionary. Any
> particular reason for this behaviour?

For a dict to be pickled all its keys and values have to be pickled, too.

More information about the Python-list mailing list