You want to use properties
class Car(object):
"""Car example with weight and speed."""
def __init__(self):
self._weight = None # internal value
self.speed = None
@property
def weight(self):
return self._weight
@weight.setter
def weight(self, the_weight):
self._weight = the_weight - 10 # or whatever here
Now, you can set speed
normally; when you execute car.weight = 20
the setter function will be called, and the actual weight will be set to 20 - 10 = 10
.