Why object.__getattribute__ and not object.__getattr__ ?

Paolo Invernizzi paoloinvernizzi at dmsware.com
Mon Oct 8 03:41:53 EDT 2001


> Why this decision to do with a long spelling of __getattribute__ but
> not __setattr__ or __delattr__ ?

Because starting from 2.2a4, the old name __getattr__ is reserved for
backward compatibility to a method that works the same way it does in
previous version...
And <object> have no implementation of it.
Basically the new name __getattribute__ is mapped to a new behaviour... and
<object> has an implementation of it...

> Also, does someone have a quick explanation of how to use __new__ handy?
> I'm not finding it in the tutorials (even the recent 2.2 specific one).

I'm using it for instantiate new instance from class using a metatype... for
ex, in a method of a class using a special MyType metatype, I'm using
something like...

newI = self.__class__.__new__(self.__class__)

Some docs can be found in the peps, but about C API only...
I'm only guessing the python use... but for my scopes for now this works..
;)

Paolo Invernizzi







More information about the Python-list mailing list