[Tutor] __getattr__(): Is this right?
Eric Brunson
brunson at brunson.com
Tue Oct 16 05:03:20 CEST 2007
Allen Fowler wrote:
>
>
> */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."
There you go, you are right and I am not. I guess because I don't
actually set the attribute of self, I can intercept both the get and set.
"Learn one new thing every day". Done. :-)
>
>
>
> ------------------------------------------------------------------------
> Building a website is a piece of cake.
> Yahoo! Small Business gives you all the tools to get online.
> <http://us.rd.yahoo.com/evt=48251/*http://smallbusiness.yahoo.com/webhosting/?p=PASSPORTPLUS>
More information about the Tutor
mailing list