Trong Python 2.5.2, đoạn mã sau đặt ra một Lỗi Loại:Python siêu() nâng 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
Nếu tôi thay thế class X
với class X(object)
, nó sẽ làm việc. Giải thích cho điều này là gì?
"tuy nhiên tôi thay thế lớp X với lớp X (đối tượng)" đã khắc phục sự cố của tôi! thanx – AliBZ