Pickling a dictionary

Ian Kelly ian.g.kelly at gmail.com
Wed Nov 7 19:03:11 CET 2012


On Wed, Nov 7, 2012 at 10:40 AM, Devashish Tyagi
<devashishrocker at gmail.com> wrote:
> Here is the code
>
> from code import InteractiveInterpreter
> import StringIO
> import pickle
>
> src = StringIO.StringIO()
> inter = InteractiveInterpreter()
> inter.runcode('a = 5')
> local = inter.locals
>
> pickle.dump(local,open('obj.dump','wb'))

After calling runcode it seems that the __builtins__ dict containing
an 'Ellipsis' binding has been added to inter.locals.  You probably
don't want to include the contents of __builtins__ in your pickle
anyway, so just delete it:

del local['__builtins__']
pickle.dump(local, ...)


More information about the Python-list mailing list