title: Python. Override a method without creating a derived class and call the original method
body: <p>I have a function like:</p>
  
  <pre><code>ModuleA.py
  
  Class FooClass:
      def fooMethod(self):
          self.doSomething()
  </code></pre>
  
  <p>Now i want to override that method, but without deriving from that class and call the overridden method from inside:</p>
  
  <pre><code>ModuleB.py
  
  from ModuleA import FooClass
  
  def _newFooMethod(self):
      if(not hasAttr(self,"varA "):
          self.varA = 0
      #Do some checks with varA
  
      #CALL ORIGINAL fooMethod
  
  FooClass.fooMethod = _newFooMethod
  </code></pre>
  
  <p>Things to know:</p>
  
  <ul>
  <li><p>I don't have access to the FooClass.</p></li>
  <li><p>I don't have access to the instances of FooClass since they are many and not in a single place.</p></li>
  <li>As you can see, what i really want is to decorate the fooMethod.</li>
  <li>I also want to create a variable like "varA" to use it in the _newFooMethod. I do that by first checking if it is already created and creating it if not, but i don't know if it is the best way to do it...</li>
  </ul>