I am trying to understand what Python's descriptors are and what they can useful for. However, I am failing at it. I understand how they work, but here are my doubts. Consider the following code:
>>> class Celsius(object):
def __init__(self, value=0.0):
self.value = float(value)
def __get__(self, instance, owner):
return self.value
def __set__(self, instance, value):
self.value = float(value)
>>> class Temperature(object):
celsius = Celsius()
Why do I need the descriptor class? Please explain using this example or the one you think is better.
What is
instance
andowner
here? (in__get__
). So my question is, what is the purpose of the third parameter here?How would I call/ use this example?
Sorry for being such a noob, but I can't really understand how to get this working.