【发布时间】:2010-10-04 02:34:40
【问题描述】:
在 Python 2.5 中,以下代码引发 TypeError:
>>> class X:
def a(self):
print "a"
>>> class Y(X):
def a(self):
super(Y,self).a()
print "b"
>>> c = Y()
>>> c.a()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in a
TypeError: super() argument 1 must be type, not classobj
如果我将class X 替换为class X(object),它将起作用。对此有何解释?
【问题讨论】:
-
您的“但是我将 X 类替换为 X 类(对象)”解决了我的问题!谢谢
标签: python inheritance python-2.x super