[Zope-dev] Re: ComputedAttribute

Chris Withers chrisw@nipltd.com
Wed, 10 Jan 2001 17:07:07 +0000


Martijn Pieters wrote:
> 
> > ...with this class, your_attribute isn't going to play in Persistence,
> > is it? (so I can update it lots without worrying about ZODB size
> > growing... :-)
> 
> Yup, this allows you to alias your_attribute to _v_your_attribute without
> creating an attribute that *will* persist in the process.

yay! :-)

> your_attribute is set to one instead of the ComputedAttribute instance and
> concequently persisted. 

d'Oh... of course...

> If you want _set_your_attribute to be called, you
> need to override __setattr__:
> 
>     def __setattr__(self, name, value):
>         setter = getattr(self, '_set_' + name, None)
>         if setter:
>             setter(value)
>         else:
>             raise AttributeError, "no such attribute: " + `name`

Hmmm... how would you change this to call the __setattr__ that was there
before you overrode it, if a setter could not be found?

cheers for all the help, this thread might make quite god docs for
ComputedAttribute ;-)

Chris