相关疑难解决方法(0)

Python super()引发了TypeError

在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
Run Code Online (Sandbox Code Playgroud)

如果我更换class Xclass X(object),它会奏效.对此有何解释?

python inheritance python-2.x super

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

标签 统计

inheritance ×1

python ×1

python-2.x ×1

super ×1