[Zope-CMF] New Product, __getattr__ and dtml-in

Dieter Maurer dieter at handshake.de
Mon Sep 13 15:14:56 EDT 2004


samuzeau at oreka.com wrote at 2004-9-13 13:17 +0200:
>I have a new product under CMF1.3/Zope2.6.0
>
>This produtc is a new Specific Type.
>In that one I have in my class:
>
>...
>def __getattr__(self, attrname ):
>if attrname == 'attrib':
>return functionlamdba()
>else:
>return getattr(self,attrname)

It is *VERY* difficult to implement a safe "__getattr__".
Therefore, you should only try when there is no other way.

Your use case can very easily be solved with an "ComputedAttribute":

     from ComputedAttribute import ComputedAttribute

     class YourClass(...):

       ...
       attrib = ComputedAttribute(functionlambda)
       ...

No need for the difficult "__getattr__"...

-- 
Dieter


More information about the Zope-CMF mailing list