title: Automatic function call on instance variable of Python class?
body: <p>So lets say I have a class called <code>Car</code> as below:</p>
  
  <pre><code>class Car(object):
      """Car example with weight and speed."""
      def __init__(self):
          self.weight = None
          self.speed = None
  </code></pre>
  
  <p>If I initialize a <code>Car</code> as an empty object:</p>
  
  <pre><code>red_car = Car()
  </code></pre>
  
  <p>And I add a <code>speed</code> and a <code>weight</code>:</p>
  
  <pre><code>red_car.speed = 60
  red_car.weight = 3500
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>def change_weight(self, any_int):
      return (any_int - 10)
  </code></pre>
  
  <p>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 <code>change_weight</code> only on the <code>weight</code> instance variable.</p>
  
  <p>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?</p>