versioned pickle module

Gerson Kurz moc.q-dnan-p at
Fri Aug 9 09:06:17 CEST 2002

# I have a class that has some data. 

class test:
    def __init__(self): = 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): = 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

More information about the Python-list mailing list