[Tutor] question about descriptors

Peter Otten __peter__ at web.de
Fri Nov 13 03:26:55 EST 2015


Albert-Jan Roskam wrote:

>> __getattr__() is only invoked as a fallback when the normal attribute
>> lookup fails:
> 
> 
> Aha.. and "normal attributes" live in self.__dict__?

I meant "normal (attribute lookup)" rather than "(normal attribute) lookup".
__getattr__() works the same (I think) when there is no __dict__: 

>>> class A(object):
...     __slots__ = ["foo"]
...     def __getattr__(self, name):
...             print "looking for", name
...             return 42
... 
>>> a = A()
>>> a.foo
looking for foo
42
>>> a.__dict__
looking for __dict__
42
>>> a.foo = "bar"
>>> a.foo
'bar'




More information about the Tutor mailing list