[Tutor] Saving Objects
Andy Cheesman
Andy.cheesman at bristol.ac.uk
Thu Jan 17 11:39:34 CET 2008
Hi people
I've written a complex program in python/numpy/scipy which creates a
dictionary of objects(which takes a while to create). I am hoping to
save these objects to disk and then access them using a different
session, thus bypassing the time to create the objects.
My initial tests using pickle and a simple class system (shown below)
have failed. The method shown below fails with a AttributeError:
'FakeModule' object has no attribute 'Spod', so when I create a
an empty class Spod in the new session, it generates an IndexError:(list
index out of range)
Is there a better way to do this?
Andy
class Spod:
def __init__(self, name):
self.name=name
fish = Spod("andy")
file = open("test.pickle","w")
pickle.dump(fish, file)
# New session
file = open("test.pickle","r")
pickle.load(file)
More information about the Tutor
mailing list