I have a class call Monkey, defined in root/ook/monkey.py. Another script, let’s call it do_things.py pickles instances of Monkey objects. The script do_things.py looks like:
import monkey
[...]
inst = monkey.Monkey()
[...]
data = cPickle.dumps(inst)
Now, I have another script called root/eek/fubar.py that looks like this:
import ook/monkey
[...]
inst = cPickle.loads(data)
Where data is the same pickled as was in do_things.py in both cases. Now, this unpickling fails because the class Monkey is not found. In this script, it is called ook.Monkey.monkey and not monkey.Monkey.
Is there any way to solve this?
Change your import in the second file from
import ook.monkeytofrom ook import monkey.