使用super()的python基类导致参数错误

时间:2015-11-19 02:25:14

标签: python

我已经编写了我的基类和子类,但是当我尝试使用pythons最新的类创建与Super时,我会发现我不熟悉的错误。但是,如果我用'Node'替换'super(Camera)',它可以正常工作。

""" 
Base class  
"""
class Node(object):
    def __init__(self, name, attributes, children):
        self.name = name
        self.attributes = attributes if attributes is not None else {}
        self.children = children if children is not None else []

"""
sub-class
"""
class Camera(Node):
    def __init__(self, name="", attributes=None, children=None, enabled=True):
        super(Camera).__init__(self, name=name, attributes=attributes, children=children)
        self.enabled = enabled

1 个答案:

答案 0 :(得分:3)

我认为你应该这样做:

super(Camera, self).__init__(name=name, attributes=attributes, children=children)