title: Python add to a function dynamically
body: <p>how do i add code to an existing function, either before or after?</p>
  
  <p>for example, i have a class:</p>
  
  <pre><code> class A(object):
       def test(self):
           print "here"
  </code></pre>
  
  <p>how do i edit the class wit metaprogramming so that i do this</p>
  
  <pre><code> class A(object):
       def test(self):
           print "here"
  
           print "and here"
  </code></pre>
  
  <p>maybe some way of appending another function to test?</p>
  
  <p>add another function such as</p>
  
  <pre><code> def test2(self):
        print "and here"
  </code></pre>
  
  <p>and change the original to</p>
  
  <pre><code> class A(object):
       def test(self):
           print "here"
           self.test2()
  </code></pre>
  
  <p>is there a way to do this?</p>