Automatic function call on instance variable of Python class?
问题 So lets say I have a class called Car as below: class Car(object): """Car example with weight and speed.""" def __init__(self): self.weight = None self.speed = None If I initialize a Car as an empty object: red_car = Car() And I add a speed and a weight : red_car.speed = 60 red_car.weight = 3500 That's all fine but what if I want to run a function when attempting to add those variables to the instance? Like this function: def change_weight(self, any_int): return (any_int - 10) The thing is