Simple Conceptual Pickling problems

Steve Holden sholden at holdenweb.com
Tue Jul 2 08:42:52 EDT 2002


"chris lyon" <chris.lyon at spritenote.co.uk> wrote ...
>
> > > SystemError: Failed to import class Programme from module __main__
> >
> > This is the hint.  The module's name when the pickle was created was
> > __main__, which only happens when the module is not imported, but is run
> > directly.  You need to pickle and unpickle from within the same context,
> > eg, use import in both cases.
> >
> > HTH,
>
> > Emile van Sebille
> > emile at fenx.com
>
> So , if I understand you, Because I ran the original code using the
> Pythonwin environment, I produced the objects in module __main__ NOT in
the
> module I though they were being created in ( in my case a module called
> octavia which contains the class Programmes).
>
> When I then ran with my test module, which imported octavia, The Unpickle
> process believed it was trying to unpickle objects defined in __main__ NOT
> from within octavia ?
>
> So should I then have a module 'above' my octavia module which will import
> octavia for it to work?
>

Correct. The unpickling will, if you let it, immport the module in which the
classes of the unpickled objects were defined. This means that they must be
recognisably from their defining module when you pickle them. As long as the
program that writes the pickle imports octavia you should be good to go.

regards
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list