[Zope] update existing instances of a class?
Sascha Ottolski
sascha.ottolski at gallileus.de
Fri Sep 10 05:10:08 EDT 2004
Am Freitag, 10. September 2004 01:14 schrieb John Schinnerer:
> Anyone know of more info anywhere on updating existing class
> instances when the class (in a python product) is modified by adding
> some properties?
>
> > Also, you could just add class variables to your object's class
> > which have sensible default.
>
> I don't understand - previous instances will not have the properties
> unless they are updated, correct?
not exactly, I think. If you change the definition of the class to have
new attributes, every instances of that class will have these
attributes, too. Of course, they will only have their default values,
all the same. but at least you can be sure that every instance has the
attributes.
next step would be to touch every instance to give them their own
values. this might be a simple as
class MyClass:
attr = None # new
attr2 = '' # new
def updateAttr(self, attr, attr2):
self.attr = attr
self.attr2 = attr2
Than you might write a PythonScript to find your instances and call the
updateAttr() method on them.
Hope that helps a bit,
Sascha
More information about the Zope
mailing list