 |
 |
 |
Python 语言参考手册Python Reference Manual |
 |
 |
3.3.2.2 Implementing Descriptors
The following methods only apply when an instance of the class
containing the method (a so-called descriptor class) appears in
the class dictionary of another new-style class, known as the
owner class. In the examples below, ``the attribute'' refers to
the attribute whose name is the key of the property in the owner
class' __dict__
.
__get__( |
self, instance, owner) |
-
Called to get the attribute of the owner class (class attribute access)
or of an instance of that class (instance attribute acces).
owner is always the owner class, while instance is the
instance that the attribute was accessed through, or
None
when
the attribute is accessed through the owner. This method should
return the (computed) attribute value or raise an
AttributeError exception.
__set__( |
self, instance, value) |
-
Called to set the attribute on an instance instance of the owner
class to a new value, value.
__delete__( |
self, instance) |
-
Called to delete the attribute on an instance instance of the
owner class.
 |
 |
 |
Python 语言参考手册Python Reference Manual |
 |
 |
版本 2.3.3, 文件最后更新时间 译文最后修改: 二月 18, 2004.