adding method to class after object creation
Hello. Can anybody help me with the following question: I havbe created zope/cmf product(e.g. LocalizedDocument) with class. User have created about 40 instances of that class in different places in zope tree. I need to add some methods to class, but how can i apply those changes(new methods) to already created objects? I have tried to add one field to class, after restarting zope that field automagically appeared in already created objects(i made catalog search and tried to access that field from python script, it worked), but i don't understand how it works and if it's usual case or i need to do something more to add new features to already created objects when doing changes in the class. Your help is very appreciated. Thanks in advance. Best regards, Ruslan
Ruslan Spivak wrote at 2003-8-19 10:24 +0300:
Can anybody help me with the following question: I havbe created zope/cmf product(e.g. LocalizedDocument) with class. User have created about 40 instances of that class in different places in zope tree. I need to add some methods to class, but how can i apply those changes(new methods) to already created objects?
This is not necessary. Unlike JavaScript, a class in Python is not a blueprint for object creation. Instead, each object contains a reference to its class. When you look up an attribute, the look up is done first in the object and then (if its fails) in its class. Therefore, when you add attributes to a class, all objects see them automatically (unless, they themselves have defined attributes of the same name). Dieter
participants (2)
-
Dieter Maurer -
Ruslan Spivak