From: John Nagle on
Bruno Desthuilliers wrote:
> And now for the most import point: __getattr__ is only called as a
> *last* resort. That is, after the attribute lookup mechanism will have
> tried *and failed* to find the name in the instance's __dict__.

In general, "getattr" is for unusual situations only.
If you want to store objects by name, use an ordinary
dict. Using "getattr" means you have to worry about clashes with
built-in names, the limitations of attribute syntax (BeautifulSoup
can be crashed by this), and some Unicode issues with attribute names.

So don't do that.

John Nagle
From: Ani Sinha on

> And now for the most import point: __getattr__ is only called as a
> *last* resort. That is, after the attribute lookup mechanism will have
> tried *and failed* to find the name in the instance's __dict__.

Thanks you all for all the suggestions and thoughts. So in other
words, this piece of code:

try:
return self.__dict__.__getitem__(item)
except KeyError:
raise AttributeError(item)

in __getattr__ is redundant.
From: Bruno Desthuilliers on
Ani Sinha a �crit :
>> And now for the most import point: __getattr__ is only called as a
>> *last* resort. That is, after the attribute lookup mechanism will have
>> tried *and failed* to find the name in the instance's __dict__.
>
> Thanks you all for all the suggestions and thoughts. So in other
> words, this piece of code:
>
> try:
> return self.__dict__.__getitem__(item)
> except KeyError:
> raise AttributeError(item)
>
> in __getattr__ is redundant.

Yeps - this is the default behaviour, and this behaviour is triggered
before any call to __getattr__ anyway.

FWIW, in your snippet, this whole __getattr__ method is useless at best.