相关疑难解决方法(0)

当父不从对象继承时,Python 2.x super __init__继承不起作用

我有以下Python 2.7代码:

class Frame:
    def __init__(self, image):
        self.image = image

class Eye(Frame):
    def __init__(self, image):
        super(Eye, self).__init__()
        self.some_other_defined_stuff()
Run Code Online (Sandbox Code Playgroud)

我正在尝试扩展该__init__()方法,以便当我实例化一个'Eye'时,除了Frame设置之外,还会做一堆其他的东西(self.some_other_defined_stuff()).Frame.__init__()需要先跑.

我收到以下错误:

super(Eye, self).__init__()
TypeError: must be type, not classobj
Run Code Online (Sandbox Code Playgroud)

其中我不明白其逻辑原因.有人可以解释一下吗?我习惯于在红宝石中输入'super'.

python inheritance super new-style-class python-2.7

25
推荐指数
2
解决办法
5万
查看次数

标签 统计

inheritance ×1

new-style-class ×1

python ×1

python-2.7 ×1

super ×1