title: In Python, can you call an instance method of class A, but pass in an instance of class B?
body: <p>In the interest of reusing some existing code that was defined as an instance method of a different class, I was tying to do something like the following:</p>
  
  <pre><code>class Foo(object):
    def __init__(self):
      self.name = "Foo"
  
    def hello(self):
      print "Hello, I am " + self.name + "."
  
  class Bar(object):
    def __init__(self):
      self.name = "Bar"
  
  
  bar = Bar()
  Foo.hello(bar)
  </code></pre>
  
  <p>but that results in:</p>
  
  <blockquote>
    <p>TypeError: unbound method hello() must be called with Foo instance as first argument (got Bar instance instead)</p>
  </blockquote>
  
  <p>Is something like this possible?</p>
  
  <hr>
  
  <p>I should have been clear that I know this is a bad idea. Obviously the real solution is a bit of refactoring. I just figured there must be a way, and it turns out there is.</p>
  
  <p>Thanks for the comments.</p>