Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?
Lacrima
lacrima.maxim at gmail.com
Sat Jul 24 03:47:04 EDT 2010
Hi!
I have two super classes:
class SuperClass1(object):
def __init__(self, word):
print word
class SuperClass2(object):
def __init__(self, word, word2):
print word, word2
Also I have subclass of these classes:
class SubClass(SuperClass1, SuperClass2):
def __init__(self):
pass
I have two questions.
1) Inside __init__ of SubClass how can I firstly call __init__ of
SuperClass1, and then __init__ of SuperClass2, using builtin super()
function.
2) Why should I use super() at all, if it is very easy to call methods
of super class like this:
class SubClass(SuperClass1, SuperClass2):
def __init__(self):
SuperClass1.__init__(self, 'Python')
SuperClass2.__init__(self, 'Hello', 'world')
Thanks in advance.
More information about the Python-list
mailing list