> To: tutor@python.org > From: __pete...@web.de > Date: Fri, 13 Nov 2015 09:26:55 +0100 > Subject: Re: [Tutor] question about descriptors > > 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'
Thank you again for the explanation. Much appreciated. I had not even thought about __slots__ yet. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor