code1:
class base(object):
def test(self):
pass
class low1(object):
def test(self):
super(low1, self).test()
print "low1 test"
class low2(object):
def test(self):
super(low2, self).test()
print "low2 test"
class high(low1, low2, base):
pass
if __name__ == "__main__":
high().test()
code2:
class base(object):
def test(self):
pass
class low1(object):
def test(self):
# super(low1, self).test()
print "low1 test"
class low2(object):
def test(self):
# super(low2, self).test()
print "low2 test"
class high(low1, low2, base):
pass
if __name__ == "__main__":
high().test()
the output of code1 is:
low2 test
low1 test
the output of code2 is:
low1 test
when I call why test method of a high object, it execute test method of both low1 and low2?
super(low2...in code1. If you are going to usesuperplease learn to understand how they work and why you might use them.super()changed a bit between Python 2 and Python 3. BTW: If you're learning Python, don't start with Python 2 but use the current version 3 from the start, it offers quite a few advantages.