Can I inherit member variables?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Sep 21 07:24:02 EDT 2006


MonkeeSage:

If you have multiple inheritance do you need the old style init anyway?

class Animal1(object):
  def __init__(self, weight, colour):
    self.weight = weight
    self.colour = colour

class Animal2(object):
  def __init__(self, name):
    self.name = name

class Bird(Animal1, Animal2):
  def __init__(self, weight, color, wingspan, name):
    super(Bird, self).__init__(weight, color) # Animal1
    Animal2.__init__(self, name)
    self.wingspan = wingspan
    print self.weight, self.colour, self.wingspan, self.name

al = Bird(12, "White", 2, "Albatross")

Bye,
bearophile




More information about the Python-list mailing list