I have seen various examples on How to use 'super' in python, but in all of these examples, there are no arguments being passed to the subclass' init method. Consider the following example.
Here is the base class:
class Animal(object):
def __init__(self, genus):
self.genus = genus
Now heres without using super:
class Dog(Animal):
def __init__(self, genus):
Animal.__init__(self, genus)
x = Dog('Canis')
print x.genus # Successfully prints "Canis"
Now when I use super instead:
class Dog(Animal):
def __init__(self, genus):
super(Animal, self).__init__(genus)
x = Dog('Canis')
print x.genus
I get the following error:
TypeError: object.__init__() takes no parameters
So then if object.init() takes no parameters, how to I set the specific genus of this particular animal when instantiated that subclass? Do I have to explicitly assign the variables like this:
class Dog(Animal):
def __init__(self, genus):
super(Animal, self).__init__()
self.genus = genus