super在单继承中使用的例子:
class Foo():
def __init__(self, frob, frotz)
self.frobnicate = frob
self.frotz = frotz
class Bar(Foo):
def __init__(self, frob, frizzle)
super().__init__(frob, 34)
self.frazzle = frizzle
此例子适合python 3.x,更多请参考super
如果要在python2.x下使用则需要稍作调整,如下代码示例:
class Foo(object):
def __init__(self, frob, frotz):
self.frobnicate = frob
self.frotz = frotz
class Bar(Foo):
def __init__(self, frob, frizzle):
super(Bar,self).__init__(frob,34)
self.frazzle = frizzle
new = Bar("hello","world")
print new.frobnicate
print new.frazzle
print new.frotz