I have an object:
class X():
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
whose attribute c, is a of list objects (of a different kind):
class Y():
def __init__(self, x, y):
self.x = x
self.y = y
I pickle this as follows:
import pickle
pickle.dump(instance_of_class_X,open(dir, "wb"))
I load as follows:
import pickle
from some_library import X, Y # I import the two classes involved
pickle.load(open(dir,"rb"))
I get the following error:
AttributeError: ‘module’ object has no attribute ‘Y’
Not sure what to do, any help would be highly appreciated.
Possibly you are falling victim to the need of
pickleto have the class available via the same fully-qualified name as was originally used. It would depend on what namespace X and Y are in when you originally create the object. See this answer and this page.