The way
__getattribute__()
works needs to be covered, as it was implemented to behave in a very specific way. Thus it is very important to recognize this ordering:
Class attributes
Data descriptors
Instance attributes
Non-data descriptors
Defaulting to __getattr__()
A descriptor is a class attribute, so all class attributes have the highest priority.……这个是在core python programming 13.16节摘录下来的,这个是让我很困惑的地方;原因在于Class attributes 与Instance attributes的优先级问题;看下面的例子:
class Test(object):
a = 15
<pre name="code" class="python">>>> t = Test()
>>> t.a
15
>>> t.a = 20
>>> t.a
20<pre name="code" class="python">>>> del t.a
>>> t.a
15</pre></pre>