title: How do I bind an existing instance method in one class to another class?
body: <p>I'm trying to do a limited form of dynamic mixin on a class, taking methods from a third-party library class and binding them to my class. But nothing I've tried has worked correctly. All examples I've seen elsewhere bind a unbound function to a class but, in my case, I need to bind an already bound method to a different class.</p>
  
  <p>Some example code I've been working with, with my failed attempts included:</p>
  
  <pre><code>import types
  import traceback
  
  class Class1(object):
      output = 'class1'
      def method(self):
          print self.output
  
  class Class2(object):
      output = 'class2'
  
  try:
      Class2.method = types.MethodType( Class1.method, None, Class2 )
      class2 = Class2()
      class2.method()
  except:
      traceback.print_exc() # TypeError: unbound method method() must be called with Class1 instance as first argument (got Class2 instance instead)
  
  try:
      class1 = Class1()
      class2 = Class2()
      class2.method = types.MethodType( class1.method, class2, Class2 )
      class2.method()
  except:
      traceback.print_exc() # TypeError: method() takes exactly 1 argument (2 given)
  
  class1 = Class1()
  class2 = Class2()
  class2.method = class1.method.__get__( class2, Class2 )
  class2.method() # outputs 'class1' not 'class2'
  </code></pre>
  
  <p>Is this possible? Am I doing something wrong? Is there another technique I haven't seen?</p>