Can anyone explain this behaviour (class attribute vs instance lookup)

Bruno da Silva de Oliveira nicoddemus at
Tue Mar 7 13:16:46 CET 2006

Hi all,

>From what I understand about the lookup semantics of instances and classes,
the following is expected:

>>> class A(object): pass
>>> A.__module__
>>> A().__module__

IOW, if an attribute is not found in the instance, it is looked-up in class,
and if found, returned. Then, I was pluzzed by this behaviour:

>>> A.__name__
>>> A().__name__
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'A' object has no attribute '__name__'

It seems that '__name__' is being treated differently somehow. I guess this
involves the descriptor machinery, but I don't know the internals of the
new-class completely to explain the above behaviour in detail. Can anyone
explain precisely the above semantics?

Best Regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list