Best way to add attributes to shelved objects?

Skip Montanaro skip at pobox.com
Fri Apr 23 15:49:43 EDT 2004


    jm> I'm working on an app that persists a few classes with shelve.  But
    jm> if I load older saved classes, I get an exception in code that uses
    jm> the new attributes, of course.

    jm> What is the best way to load these older classes, check for the new
    jm> attributes, and add them so they will work with the new code?

Why not check for those attributes in your __getstate__ method and add
default (or computed) values for any missing attributes?

Skip




More information about the Python-list mailing list