Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The article glosses over some details. When you have questions like this, it's time to turn to an authoritative source, which in this case is The Python Language Reference, section <a href="http://docs.python.org/2/reference/datamodel.html#the-standard-type-hierarchy" rel="nofollow">3.2. The standard type hierarchy</a>, which contains an entry for classes which states (my emphasis):</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., <code>C.x</code> is translated to <code>C.__dict__["x"]</code> (although for new-style classes in particular there are a number of hooks which allow for other means of locating attributes). <strong>When the attribute name is not found there, the attribute search continues in the base classes</strong>.</p> </blockquote> <p>This is describing attribute lookup for classes, not class instances, and i believe it explains what is happening in your code.</p> <p>For completeness, here's what the next entry, about class instances, says:</p> <blockquote> <p>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>I take "the search continues with the class attributes" as meaning "repeat the procedure given for classes", ie search the base classes. Inheritance would be rather less useful if it didn't!</p> <p>The article you link to explains attribute lookup for class instances, but it doesn't say anything about attribute lookup for classes. Because it doesn't, it gives the impression that it works the same way, which is not the case.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload