Why object.__getattribute__ and not object.__getattr__ ? 
Author Message
 Why object.__getattribute__ and not object.__getattr__ ?

  >>> dir(object)
  ['__class__', '__delattr__', '__getattribute__', '__hash__', '__init__',
   '__new__', '__reduce__', '__repr__', '__setattr__', '__str__']

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

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).

Kirby



Thu, 25 Mar 2004 01:45:07 GMT  
 Why object.__getattribute__ and not object.__getattr__ ?

Quote:
> 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...

Quote:
> 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



Fri, 26 Mar 2004 15:41:53 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Question about __getattribute__/__getattr__

2. Why new is not a message of Object?

3. Proposal: why not make all objects hashable ?

4. DupByteArrayInternalRep does not set object type of new object

5. getattr on objects

6. __getattr__ and extend COM object

7. function-objects and code-objects ( was: re-creating objects and security )

8. Java Object Not Returned/Java Class Not Preserved

9. APL Objects: DCOs (Dyalog Component Objects)

10. Correct way of invoking an object inside an ole object

11. Survey referencing objects to an object

12. Class objects , instance objects

 

 
Powered by phpBB® Forum Software