【发布时间】:2014-05-31 19:32:45
【问题描述】:
我有以下 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()
我正在尝试扩展__init__() 方法,以便当我实例化一个“Eye”时,除了Frame 设置的内容之外,它还会执行许多其他操作(self.some_other_defined_stuff())。 Frame.__init__() 需要先运行。
我收到以下错误:
super(Eye, self).__init__()
TypeError: must be type, not classobj
我不明白其中的逻辑原因。有人可以解释一下吗?我习惯于在 ruby 中输入“super”。
【问题讨论】:
-
Frame必须扩展object。super仅适用于新型类。
标签: python python-2.7 inheritance super new-style-class