相关疑难解决方法(0)

Python中的旧样式和新样式类有什么区别?

Python中的旧样式和新样式类有什么区别?我什么时候应该使用其中一种?

python oop types class new-style-class

953
推荐指数
8
解决办法
22万
查看次数

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万
查看次数

标签 统计

python ×2

class ×1

inheritance ×1

new-style-class ×1

oop ×1

python-2.x ×1

super ×1

types ×1