title: How to extend class method
body: <p>Both <code>SubClassA</code> and <code>SubClassB</code> are the sub-classes of <code>Base</code> class (both inherit from same <code>Base</code> class). Since <code>getInfo()</code> method is declared within <code>Base()</code> class it (this method) is shared between both A and B sub-classes. When <code>getInfo()</code> method is called it returns the value of <code>self.attr</code> variable (shared among A and B sub-classes). Now I want to "extend" this method. So when it is called via subClassA instance using <code>instanceA.getInfo()</code> <strong>in addition to</strong> <code>self.attr</code> it would return <code>self.attrA</code> as well. Likewise if instanceB is used: <code>instanceB.getInfo()</code> <code>self.attrB</code> is returned in addition to returning <code>self.attr</code>. How <code>Base()</code> class's method <code>getInfo()</code> can be extended so it is "customized" for both sub-classes A and B?</p>
  
  <pre><code>class Base(object):
      def __init__(self):
          super(Base, self).__init__()
          self.attr='Attr'
  
      def getInfo(self):
          info=self.getAttr()
          return info
      def getAttr(self):
          return self.attr
  
  class SubClassA(Base):
      def __init__(self):
          super(SubClassA, self).__init__()  
          self.attrA='attrA'      
      def getAttrA(self):
          return self.attrA
  
  class SubClassB(Base):
      def __init__(self):
          super(SubClassB, self).__init__()  
          self.attrB='attrB'      
      def getAttrB(self):
          return self.attrB
  
  instanceA=SubClassA()
  instanceB=SubClassB()
  print instanceA.getInfo()
  print instanceB.getInfo()
  </code></pre>