Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From the <a href="http://docs.python.org/reference/datamodel.html#implementing-descriptors" rel="nofollow noreferrer">documentation</a>:</p> <blockquote> <p>The following methods only apply when an instance of the class containing the method (a so-called descriptor class) appears in an owner class (the descriptor must be in either the owner’s class dictionary or in the class dictionary for one of its parents).</p> </blockquote> <p>So descriptors (ie. objects that implement <code>__get__</code>, <code>__set__</code> or <code>__delete__</code>) must be members of a class, NOT an instance.</p> <p>With the followinging changes:</p> <pre><code>Temperature.celsius2 = Celsius() T = Temperature() print('T.celsius:', T.celsius) print('T.celsius1:', T.celsius1) print('T.celsius2:', T.celsius2) </code></pre> <p>The output is:</p> <pre><code>T.celsius: 0.0 T.celsius1: &lt;__main__.Celsius object at 0x7fab8c8d0fd0&gt; T.celsius2:, 0.0 </code></pre> <p>More links:</p> <ul> <li><a href="http://docs.python.org/howto/descriptor.html" rel="nofollow noreferrer">Descriptor HowTo Guide</a>.</li> <li><a href="https://stackoverflow.com/questions/3798835/understanding-get-and-set-and-python-descriptors">Understanding __get__ and __set__ and Python descriptors</a></li> <li><a href="http://martyalchin.com/2007/nov/23/python-descriptors-part-1-of-2/" rel="nofollow noreferrer">http://martyalchin.com/2007/nov/23/python-descriptors-part-1-of-2/</a></li> <li><a href="https://www.google.com/?q=python%20descriptors" rel="nofollow noreferrer">https://www.google.com/?q=python%20descriptors</a></li> </ul>
 

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