Hi again Im doing some product-stuff and have reached a point where its necessary that som instances of the same product-type share a property (class attribute). How do I do this in Zope and Python? Regards Danny Nielsen
Class attributes can be used in Zope just like in normal Python with one large caveat: Changes to class attributes are not persisted. Therefore it is only useful for constant values that are changed only at dev time. To share values that change, you can use Zope's acquisition machinery. A simple way to do this is to create a property in a folder above all of the instances of your class (like in the root folder). You can then acquire this property value like its an attribute of the object: v = self.some_property_name However, it would probably be better to have a sensible default such as: try: v = self.some_property_name except AttributeError: v = some_default You can also be explicit in your code by declaring this value as acquired: from Acquisition import Acquired class Stuff(SimpleItem): some_propery_name = Acquired() def someMethod(self): try: v = self.some_property_name except AttributeError: v = some_default ... Then at least you have some indication where "property_name" comes from in your code. hth, -Casey On Thursday 27 March 2003 02:37 am, Danny wrote:
Hi again
Im doing some product-stuff and have reached a point where its necessary that som instances of the same product-type share a property (class attribute). How do I do this in Zope and Python?
Regards
Danny Nielsen
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
participants (2)
-
Casey Duncan -
Danny