class Circle:
def __init__(self, radius):
self.radius = radius
@property
def radius(self):
return self.diameter / 2.0
@radius.setter
def radius(self, radius):
self.diameter = radius * 2.0
foo = Circle(5)
print(foo.radius)
Sorry if I am asking this in the wrong way. The above code (from Raymond Hettinger's talk) runs perfectly fine. However, I cannot understand how/when the setter is actually being called, or how it is receiving "radius" variable to set the diameter.
I thought that for a setter must be called with parameter, e.g. self.radius(radius), or from outside the class, foo.radius(radius)
Here it must be the case that the setter is accessing the radius parameter passed from outside the class and assigning it to diameter.