[Zope-dev] How to override __getattr__ and not break acquisition
Steve Alexander
steve@cat-box.net
Thu, 17 Oct 2002 13:20:39 +0000
> I perhaps should have clarified that I need to be able to specify the
> name of the attributes or methods at run time, so ComputedAttribute
> unfortunately won't do the trick as you have to define each
> attribute/method you require in the class definition.
>
> ie. I need something like :
> def __getattr__(self,attr):
> if name in self.methodlist:
> <do something>
> return Implicit.__class__.__getattr__(self,attr)
>
> where self.methodlist is a list of strings that may change per instance
> and/or at runtime, or itself could be calculated at the time of doing
> the __getattr__ (eg self.getMethodList()).
Sounds like you could use ZPatterns.
If you do implement your own __getattr__, you might need to check if the
object you want to return implements __of__, and return
object.__of__(self) (or something like that).
--
Steve Alexander