我做了研究,是的,实例变量和属性是不同的,这是因为类实例和类有单独的字典。正如documentation中所说: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.
所以基本上Noddy结构包含实例变量。Noddy_成员持有属性。此外:Attribute assignments and deletions
update the instance’s dictionary,
never a class’s dictionary. If the
class has a setattr() or
delattr() method, this is called instead of updating the instance
dictionary directly.
同时:If a class attribute is found that is
a user-defined function object or an
unbound user-defined method object
whose associated class is the class
(call it C) of the instance for which
the attribute reference was initiated
or one of its bases, it is transformed
into a bound user-defined method
object whose im_class attribute is C
and whose im_self attribute is the
instance. Static method and class
method objects are also transformed,
as if they had been retrieved from
class C; see above under “Classes”.
See section Implementing Descriptors
for another way in which attributes of
a class retrieved via its instances
may differ from the objects actually
stored in the class’s dict. If no
class attribute is found, and the
object’s class has a getattr()
method, that is called to satisfy the
lookup.