Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在从对象继承的类中,super()和_init__;()的行为是什么?_Python_Inheritance_Language Implementation - Fatal编程技术网

Python 在从对象继承的类中,super()和_init__;()的行为是什么?

Python 在从对象继承的类中,super()和_init__;()的行为是什么?,python,inheritance,language-implementation,Python,Inheritance,Language Implementation,使用带有新类样式的python 2.7,如果我的类继承自对象类,那么super(ClassName,self)的行为是什么?我的意思是,幕后发生了什么?如果我省略了它,有什么区别 上面的一个例子: class ClassName(object): """docstring for ClassName""" def __init__(self, arg): super(ClassName, self).__init__() ## The question abo

使用带有新类样式的python 2.7,如果我的类继承自
对象
类,那么
super(ClassName,self)的行为是什么?我的意思是,幕后发生了什么?如果我省略了它,有什么区别

上面的一个例子:

  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
如果我省略了超级
,那么幕后会发生什么


谢谢。

在单一继承的情况下,绝对没有什么<代码>对象。uuu init_uuuu()做下蹲动作


在的情况下,不调用一个完整的。这对应用程序的影响各不相同,但通常不是一件好事。

请注意,在
其他类中调用
super
是不安全的,因为无法保证MRO中的下一个类允许使用参数
\uu init\uuu
(例如,因为它可能是
对象
)。