[Zope-dev] Re: ComputedAttribute
Martijn Pieters
mj@digicool.com
Wed, 10 Jan 2001 18:43:03 +0100
On Wed, Jan 10, 2001 at 05:07:07PM +0000, Chris Withers wrote:
> > 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?
The same way you call any overridden method, by calling it on the class
you inherit it from.
So:
class Foo:
def __setattr__(self, name, value):
# Whatever
pass
class Bar(Foo):
def __setattr__(self, name, value):
Foo.__setattr__(self, name, value)
# More whatever
--
Martijn Pieters
| Software Engineer mailto:mj@digicool.com
| Digital Creations http://www.digicool.com/
| Creators of Zope http://www.zope.org/
---------------------------------------------