I’m playing around with Python properties and was curious about the setter.
Using the @property
decorator, I can easily set both getter and setter:
class Testing:
def __init__(self,value):
self.value = value
@property
def thing(self):
return self.value * 2
@thing.setter
def thing(self,value):
self.value = value * 3
I’ve tried to follow this pattern without the decorator:
class Testing:
def __init__(self,value):
self.value = value
def getthing(self):
return self.value * 2
def setthing(self,value):
self.value = value * 3
thing = property(getthing)
# setter?
I know I can set both using property(getthing,setthing)
, but is it possible to set the setter separately? This is partly to get to know the property()
function better, but also because it might be possible to change to a different property later.