[Zope3-Users] property in view/adapter

Benji York benji at zope.com
Wed May 11 09:04:54 EDT 2005


Marc Rijken wrote:
> class Object:
>     def __init__(self):
>         self.attributes = {}
> 
> class NamedObject:
>     def __init__(self, context):
>         self.context = context
> 
>     def getName(self, type):
>         return self.context.attributes[type]
> 
>     def setName(self, type, value):
>         self.context.attributes[type] = value
> 
> def nameProperty(type):
>     fget = lambda self: self.getName(type)
>     fset = lambda self, value: self.setName(type, value)
>     return property(fget, fset)
> 
> class Person(NamedObject):
> 
>     firstname = nameProperty('firstname')

> It looks like property can not be used as setter in views/adapters. Is 
> that the problem? Or is there an other problem?

It doesn't have anything to do with views or adapters, or even
Zope. :)

Properties only work properly on new style classes.  Change the line 
"class NamedObject:" to "class NamedObject(object):" and it will work.
-- 
Benji York
Sr. Software Engineer
Zope Corporation


More information about the Zope3-users mailing list