general class functions
Dan Perl
danperl at rogers.com
Wed Nov 3 15:34:17 EST 2004
"syd" <syd.diamond at gmail.com> wrote in message
news:a76ba315.0411030822.7e48d308 at posting.google.com...
> Andrea Griffini <agriff at tin.it> wrote in message
>
>> Would it be worse or better to make Library a new-style
>> class, using __getattribute__ instead of __getattr__ and
>> defaulting to object.__getattribute__(self,name) in the
>> "else" part ?
>
> Can you elaborate here, please? I'm not sure I understand what you mean.
__getattr__ existed since "classic" classes. It is only called if the
regular way of searching for the attribute doesn't find it (it's not in
self.__dict__). __getattribute__ was introduced with new style classes and
it is called for *all* attribute references. In your case at least, you can
either implement the __getattr__ hook or override the __getattribute__
method with pretty much the same results. I see a use in overriding
__getattribute__ if you want to change the behavior for all the attributes,
but you are interested only in "get_*" methods.
Again, see http://www.python.org/2.2.1/descrintro.html for more (I was
actually loosely quoting from there in my explanation).
I can't say though whether it would be worse or better. I'm also curious to
hear opinions on that.
Dan
More information about the Python-list
mailing list