[Tutor] __getattr__(): Is this right?

Allen Fowler allen.fowler at yahoo.com
Tue Oct 16 04:56:47 CEST 2007



Eric Brunson <brunson at brunson.com> wrote: Allen Fowler wrote:
> I seem to be having an issue with __getattr__() being called even if 
> the proporite already exists... I thought that this was not supposed 
> to happen.

I think you've misunderstood.  __getattr__() should always be called, it
allows you to intercept and reimplement the behavior of a attribute
lookup to suit your needs.  Typically, my __getattrs__() look like this:



See:
http://docs.python.org/ref/attribute-access.html


This would lead me to think not that way...


"Note that if the attribute is found through the normal mechanism, __getattr__() is not called.  (This is an intentional asymmetry between __getattr__() and __setattr__().) This is done both for efficiency reasons and because otherwise __setattr__() would have no way to access other attributes of the instance."




       
---------------------------------
Building a website is a piece of cake. 
Yahoo! Small Business gives you all the tools to get online.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071015/085119e6/attachment.htm 


More information about the Tutor mailing list