|Python Language Reference Manual|
by Guido van Rossum and Fred L. Drake, Jr.
Paperback (6"x9"), 120 pages
RRP £12.95 ($19.95)
Sales of this book support the Python Software Foundation! Get a printed copy>>>
126.96.36.199 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
__dict__ of the owner class. Descriptors can only be implemented as
new-style classes themselves.
__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 access).
owner is always the owner class, while instance is the
instance that the attribute was accessed through, or
Nonewhen the attribute is accessed through the owner. This method should return the (computed) attribute value or raise an
__set__(self, instance, value)
- Called to set the attribute on an instance instance of the owner class to a new value, value.
- Called to delete the attribute on an instance instance of the owner class.
|ISBN 0954161785||Python Language Reference Manual||See the print edition|