__getattribute__ doesn't work on 'type' type for '__class__'

Barry Kelly barry.j.kelly at gmail.com
Tue Jun 20 12:36:17 EDT 2006


I'm running this version of Python:

  Python 2.4.3 (#1, May 18 2006, 07:40:45) 
  [GCC 3.3.3 (cygwin special)] on cygwin

I read in the documentation that these two expressions are
interchangeable:

  x.__getattribute__('name') <==> x.name

>From "pydoc __getattribute__":

---8<---
Help on method-wrapper object:

__getattribute__ = class method-wrapper(object)
 |  Methods defined here:
 |  
 |  __call__(...)
 |      x.__call__(...) <==> x(...)
 |  
 |  __getattribute__(...)
 |      x.__getattribute__('name') <==> x.name
--->8---

Yet when I try this with the 'type' type, it doesn't work:

---8<---
>>> x.__class__.__class__
<type 'type'>
>>> x.__class__.__getattribute__('__class__')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: descriptor '__getattribute__' requires a 'int' object but
received a 'str'
--->8---

Why is this?

-- Barry

-- 
http://barrkel.blogspot.com/



More information about the Python-list mailing list