使用带有新类样式的python 2.7,如果我的类继承自Object
类,那么行为是super(ClassName, self).__init__()
什么?我的意思是,幕后发生了什么?如果我省略它有什么区别?
上面的一个例子:
class ClassName(object):
"""docstring for ClassName"""
def __init__(self, arg):
super(ClassName, self).__init__() ## The question above is about this super
self.arg = arg
class OtherClass(ClassName):
"""docstring for OtherClass"""
def __init__(self, arg, otherArg):
super(OtherClass, self).__init__(arg) ## The question below is about this super
self.otherArg = otherArg
如果我省略了super
,幕后会发生什么?
谢谢。