Why are the lookup procedures for getting an attribute from a class and from an instance different?
问题 Python in a Nutshell describes the lookup procedures when getting an attribute. The book distinguishes two cases the lookup procedure when getting an attribute from a class, e.g. cls.name Getting an attribute from a class When you use the syntax C.name to refer to an attribute on a class object C , the lookup proceeds in two steps: When name is a key in C.__dict__ , C.name fetches the value v from C.__dict__['name'] . Then, when v is a descriptor (i.e., type(v) supplies a method named __get__