[issue14290] Importing script as module causes ImportError with pickle.load

Floris Bruynooghe report at bugs.python.org
Sat Jul 7 13:46:46 CEST 2012


Floris Bruynooghe <floris.bruynooghe at gmail.com> added the comment:

Hi, I think this is a usage error and if not you should try to provide a test case with both files for this.

Pickle needs to be able to import the module which contains the classes by the same name as the original module.  That means pickling an instance of a class defined in a script will not work unless it is the same script which did the pickling.  The object is probably pickled under the name __main__.YourClass and when you import it in another script it will be objectScript.YourClass, hence pickle is unable to find the class for the object you are trying to unpickle.

----------
nosy: +flub

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14290>
_______________________________________


More information about the Python-bugs-list mailing list