Does anyone know how to pickle classes that have classes within them? I get back the top level attributes, but not the attributes under them.
import pickle class authorObj(): class authors(): pass q = authorObj() q.authors.name = 'somebody' output = open('test.pkl', 'wb') pickle.dump(q, output) output.close()
gives me no error
but when i try to unpickle the data, I lose the attributes under author (the top level attribute)
>>> pkl_file = open('test.pkl', 'rb') >>> q = pickle.load(pkl_file) >>> pkl_file.close() >>> q.authors.t Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> q.authors.t AttributeError: class authors has no attribute 't'
Does anyone know how to save such an object?