SystemError in Learning Python Example

kopecjc kopecjc at worldnet.att.net
Wed Dec 22 00:21:15 EST 1999


You were right -- thanks alot!  I had pickled with FeedbackData in a
script which, though it was named "feedback.py", was interpreted as the
"__main__" module, and attempted to unpickle from a program that
imported the "feedback" module -- thus the same file was viewed as
having different module name depending on its context. (Note that the
file was using the "if __name__ = __main__" trick to allow it to be both
used as a main module and to be imported.)  I have revised the pickling
script to split off class FeedbackData into a "feedback" module and no
longer get the SystemError (I subsequently get a "KeyError: #" message,
but I do not think that it is necessarily a result of my original
problem).  I guess what happens is that pickling serializes the class
name, as well as the module name, and that unpickling can decode the
class/module pair only if the same class, in a module with the same
name, is available.  It should be noted that "Learning Python" actually
addresses this issue in a sidebar on page 285 -- I had skipped over this
section because it was an example of interfacing with COM and I am
running Linux.

Fredrik Lundh wrote:
> 
> kopecjc <kopecjc at worldnet.att.net> wrote:
> > I am pretty sure that all the required files on the right
> > paths.  Does anyone know what could be causing the "SystemError"
> > message?  I would have thought that FeedbackData is from module
> > feedback, not __main__.  Does anyone have any idea why the pickle module
> > would have expected it to be from __main__?
> 
> probably because you created the pickle by running
> the program as:
> 
>     $ python feedback.py
> 
> this executes the code in feedback.py in a module
> called "__main__".  if you read the pickle from another
> script, it's quite likely are that you don't have the same
> class in that script...
> 
> to make pickle work properly with classes, put the class
> definitions in a separate module, and import it into your
> main script.
> 
> </F>



More information about the Python-list mailing list