python2.7 使用super关键词 报错 TypeError: must be type, not classobj 解决办法,typeerrorclassobj,今天遇到这个错误:Tra
python2.7 使用super关键词 报错 TypeError: must be type, not classobj 解决办法,typeerrorclassobj,今天遇到这个错误:Tra
今天遇到这个错误:
Traceback (most recent call last): File "t2.py", line 14, in <module> print Derived().meth() File "t2.py", line 10, in meth super(Derived,self).meth()TypeError: must be type, not classobj
试验代码如下:
class Base(): def meth(self): print "i'm base" class Derived(Base): def meth(self): super(Derived,self).meth() print "this is derived" print Derived().meth()
google了下,发现原因是:
super只能用于python的新类中,如果基类是经典类,则会报这个错。
新类和经典类又是什么呢?
新类:所有类都必须要有继承的类,如果什么都不想继承,就继承到object类。
经典类:什么都不用继承的类,如上面的代码就是经典类。所以报错。
class Base(object): def meth(self): print "i'm base"
相关内容
- python通过urlparse分析处网址中的域名,pythonurlparse,impo
- python通过参数方式向mysql中添加数据,pythonmysql,#!/usr/
- python数组插入新元素,python数组新元素,li=['a', 'b'
- 用Python实现一个简单的算术游戏,python实现算术,#!/us
- 在windows下安装python的easy_install工具,pythoneasy_install,在
- python通过cStringIO实现临时内存文件访问,pythoncstringio
- python通过wxPython打开并播放wav文件,pythonwxpython,''' wx_
- python计算牛顿迭代多项式,python牛顿多项式,''' p = eva
- N lowest eigenvalues of the tridiagonal matrix in python,,''' r = l
- python实现二分查找代码演示,python二分,def BinarySe
评论关闭