title: Trying to use the same method in multiple inherited classes with different attributes
body: <p>I'm trying to figure out how to roughly do what is below.  Some things will only have <code>foo</code>, some will have both <code>foo</code> and <code>bar</code>, and some will have <code>foo</code>, <code>bar</code>, and <code>baz</code>.  I would like to be able to either call <code>Child.calc(10)</code> or <code>GrandChild.calc(10)</code> and get the attributes set correctly as needed.</p>
  <p>At the end of building out multiple instances of Initial, Child, and Grandchild, I would like to just call calc on any of them and have it work, regardless of what class they are.  Initially I was going to do calc_initial, calc_child, calc_grandchild, but that seemed wrong.</p>
  <p>Initial Code</p>
  <pre class="lang-py prettyprint-override"><code>class Initial:
      def __init__(self, foo):
          self.foo = foo
  
      def Calc(self, amount):
          self.TotalFoo = self.foo * amount
  
  class Child(Initial):
      def __init__(self, foo, bar):
          Initial.__init__(self, foo)
          self.bar = bar
  
      def Calc(self, amount):
          self.TotalBar = self.bar * amount
  
  class GrandChild(Child):
      def __init__(self, foo, bar, baz):
          Child.__init__(self, foo, bar)
          self.baz = baz
  
      def Calc(self, amount):
          self.TotalBaz = self.baz * amount
  
  
  GrandChild(10, 20, 30)
  GrandChild.Calc(10)
  print(GrandChild.TotalFoo)  # Want this to be 100
  print(GrandChild.TotalBar)  # Want this to be 200
  print(GrandChild.TotalBaz)  # Want this to be 300
  </code></pre>
  <p>Edited Code Thanks to mkrieger1</p>
  <pre class="lang-py prettyprint-override"><code>class Initial:
      def __init__(self, foo):
          self.foo = foo
  
      def calc(self, amount):
          self.total_foo = self.foo * amount
  
  class Child(Initial):
      def __init__(self, foo, bar):
          Initial.__init__(self, foo)
          self.bar = bar
  
      def calc(self, amount):
          Initial.calc(self, amount)
          self.total_bar = self.bar * amount
  
  class GrandChild(Child):
      def __init__(self, foo, bar, baz):
          Child.__init__(self, foo, bar)
          self.baz = baz
  
      def calc(self, amount):
          Child.calc(self, amount)
          self.total_baz = self.baz * amount
  
  child = Child(2,4)
  grandchild = GrandChild(10, 20, 30)
  child.calc(10)
  grandchild.calc(10)
  print(child.total_foo)       # Want this to be 20 
  print(child.total_bar)       # Want this to be 40
  print(grandchild.total_foo)  # Want this to be 100
  print(grandchild.total_bar)  # Want this to be 200
  print(grandchild.total_baz)  # Want this to be 300
  </code></pre>
  <p>Trying to incorporate super but it feels like something is wrong.  Results are correct but not sure.</p>
  <pre class="lang-py prettyprint-override"><code>class Initial:
      def __init__(self, foo):
          self.foo = foo
  
      def calc(self, amount):
          self.total_foo = self.foo * amount
  
  class Child(Initial):
      def __init__(self, foo, bar):
          Initial.__init__(self, foo)
          self.bar = bar
  
      def calc(self, amount):
          super().calc(amount)
          self.total_bar = self.bar * amount
  
  class GrandChild(Child):
      def __init__(self, foo, bar, baz):
          Child.__init__(self, foo, bar)
          self.baz = baz
  
      def calc(self, amount):
          super().calc(amount)
          self.total_baz = self.baz * amount
  
  child = Child(2,4)
  grandchild = GrandChild(10, 20, 30)
  child.calc(10)
  grandchild.calc(10)
  print(child.total_foo)       # Want this to be 20 
  print(child.total_bar)       # Want this to be 40
  print(grandchild.total_foo)  # Want this to be 100
  print(grandchild.total_bar)  # Want this to be 200
  print(grandchild.total_baz)  # Want this to be 300
  </code></pre>
  <p>When trying to do elder's response</p>
  <pre><code>class Initial:
      def __init__(self, foo):
          self.foo = foo
  
      def calc(self, amount):
          self.total_foo = self.foo * amount
  
  class Child(Initial):
      def __init__(self, foo, bar):
          super().__init__(foo)
          self.bar = bar
  
      def calc(self, amount):
          self.total_bar = self.bar * amount
  
  class GrandChild(Child):
      def __init__(self, foo, bar, baz):
          super().__init__(foo, bar)
          self.baz = baz
  
      def calc(self, amount):
          self.total_baz = self.baz * amount
  
  child = Child(2,4)
  grandchild = GrandChild(10, 20, 30)
  child.calc(10)
  grandchild.calc(10)
  print(child.total_foo)       # Want this to be 20 
  print(child.total_bar)       # Want this to be 40
  print(grandchild.total_foo)  # Want this to be 100
  print(grandchild.total_bar)  # Want this to be 200
  print(grandchild.total_baz)  # Want this to be 300
  </code></pre>
  <p>I get</p>
  <pre><code>     26 child.calc(10)
       27 grandchild.calc(10)
  ---&gt; 28 print(child.total_foo)       # Want this to be 20
       29 print(child.total_bar)       # Want this to be 40
       30 print(grandchild.total_foo)  # Want this to be 100
  
  AttributeError: 'Child' object has no attribute 'total_foo'
  </code></pre>