擅长:python、mysql、java
<p>引用<a href="http://docs.python.org/reference/datamodel.html">http://docs.python.org/reference/datamodel.html</a>中的<code>Classes</code>和<code>Class instances</code>部分</p>
<blockquote>
<p>A class has a namespace implemented by a dictionary object. Class
attribute references are translated to lookups in this dictionary,
e.g., C.x is translated to C.__dict__["x"] (although for new-style classes in particular there are a number of hooks which allow for other means of locating attributes)</p>
<p>A class instance is created by calling a class object (see above). A
class instance has a namespace implemented as a dictionary which is
the first place in which attribute references are searched. When an
attribute is not found there, and the instance’s class has an
attribute by that name, the search continues with the class
attributes.</p>
</blockquote>
<p>一般来说,这种用法很好,除了“特别是新样式的类,有许多钩子允许其他方式定位属性”这样的特殊情况。</p>