You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I implemented a data-structure as an object in a script, let's call it objectScript.py. I'm using this data-structure in other scripts like so:
fromobjectScriptimportdata-structure
Populating this data-structure requires quite a bit of time, so when I'm done with it, I like to pickle it. However, if I try to load it from the pickled file, I get the following error:
ImportError: No module named objectScript
However, if I replace my 'from objectScript import data-structure' statement with the actual data-structure class definition from the objectScript.py file when I am pickling the object but then revert to the import statement when I am unpickling the object, everything works fine.
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.
Without a test case, we cannot tell if this is a bug in pickle or not. Anyhow, Floris's explanation is pretty much on the dot as why you might see this error.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: