在Python 2.5.2,下面的代碼引發一個類型錯誤:Python的超()提出了類型錯誤
>>> 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」修復了我的問題! thanx – AliBZ 2013-05-24 17:35:45