Lost in descriptor land

Lawrence D’Oliveiro lawrencedo99 at gmail.com
Thu Jun 30 23:43:05 EDT 2016


On Friday, July 1, 2016 at 1:06:12 PM UTC+12, Ankush Thakur wrote:
> 1) I don't get the idea behind the 'instance' and 'owner' parameters at
> all. Is there some simple tutorial that can explain these?

Read the GvR blog post I referenced separately. Then after that, the relevant section of the language reference <https://docs.python.org/3/reference/datamodel.html#descriptors> should make a little bit more sense.

Remember, a descriptor has its own class. You can have multiple instances of this class attached to the same owner class. The actual values you want each descriptor instance to get and set are attached to *instances* of the owner class.

> Shouldn't we be instead using self.celcius in, say, __init__() and then
> everything will work fine?

I guess it might. But this way, using descriptors, all the setup is done once at class definition, rather then every time in class instantiation.



More information about the Python-list mailing list