versioned pickle module
Gerson Kurz
moc.q-dnan-p at p-nand-q.com
Fri Aug 9 03:06:17 EDT 2002
# I have a class that has some data.
class test:
def __init__(self):
self.foo = 123
# It is stored in pickle files for object
# persistence accross program # starts.
import pickle
objects = [test(), test(), test()]
pickle.dump(objects, file("temp.dat","w"))
...
objects = pickle.load( file("temp.dat") )
# now, some time later the class definition
# changes, maybe even in some incompatible manner
class test:
def __init__(self, bar):
self.bar = bar
objects = pickle.load( file("temp.dat") )
# now, objects contains instances of the "old" class.
Question: is there a default / recommended way to provide a save
merging of old/new class definitions? I could imagine something that
involves __dict__ and copying all old attributes to instances of a new
class.
More information about the Python-list
mailing list