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 though I want it to automatically run this function whenever I attempt to add specific instance variables to the object. If possible I would like it to run change_weight only on the weight instance variable.
Am I understanding this correctly or should I just be running the integer through the function separately and then adding to the object after manually?
properties