N
Nick
I've got a collection of classes describing animals, part of which looks
like:
class Animal(object):
def __init__(self):
self.pet = False
self.edible = False
self.legs = 0
self.sound = None
self.name = self.__class__.__name__.lower()
class Mammal(Animal):
def __init__(self):
Animal.__init__(self)
self.legs = 4
class Primate(Mammal):
def __init__(self):
Mammal.__init__(self)
self.legs = 2
class Human(Mammal):
def __init__(self):
Primate.__init__(self)
self.sound = "Hey, I can talk!"
I want to add a "pedigree" function to Animal so that I can have:
I've been thinking about something like:
def pedigree(self):
n = self.name
while n != 'object' # base class of Animal
print n,
n = Well, this is where I'm stuck. super(???,???).???
print
Oh, and while the gurus are at it, what would be the advantage (if any) of
changing, say
Primate.__init__(self)
to
super(Human, self).__init__()
Thanks, all,
Nick.
like:
class Animal(object):
def __init__(self):
self.pet = False
self.edible = False
self.legs = 0
self.sound = None
self.name = self.__class__.__name__.lower()
class Mammal(Animal):
def __init__(self):
Animal.__init__(self)
self.legs = 4
class Primate(Mammal):
def __init__(self):
Mammal.__init__(self)
self.legs = 2
class Human(Mammal):
def __init__(self):
Primate.__init__(self)
self.sound = "Hey, I can talk!"
I want to add a "pedigree" function to Animal so that I can have:
I've been thinking about something like:
def pedigree(self):
n = self.name
while n != 'object' # base class of Animal
print n,
n = Well, this is where I'm stuck. super(???,???).???
Oh, and while the gurus are at it, what would be the advantage (if any) of
changing, say
Primate.__init__(self)
to
super(Human, self).__init__()
Thanks, all,
Nick.