python:TypeError: must be type, not classobj
2012-08-24 03:37
771 查看
今天遇到这个错误:
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
试验代码如下:
google了下,发现原因是:
super只能用于python的新类中,如果基类是经典类,则会报这个错。
新类和经典类又是什么呢?
新类:所有类都必须要有继承的类,如果什么都不想继承,就继承到object类。
经典类:什么都不用继承的类,如上面的代码就是经典类。所以报错。
本文出自 “YEELONⒼ ” 博客,请务必保留此出处http://yeelone.blog.51cto.com/1476571/971591
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"
本文出自 “YEELONⒼ ” 博客,请务必保留此出处http://yeelone.blog.51cto.com/1476571/971591
相关文章推荐
- [转载]python中super出现的TypeError: must be type, not classobj 原因及解决
- python中super出现的TypeError: must be type, not classobj 原因及解决
- python中super出现的TypeError: must be type, not classobj 原因及解决
- python2.7 使用super关键词 报错 TypeError: must be type, not classobj 解决办法
- python出现super.__init__:TypeError:must be type,not classobj
- python2.7 使用super关键词 报错 TypeError: must be type, not classobj 解决办法
- python中super()出现的TypeError: must be type, not classobj
- python中super出现的TypeError: must be type, not classobj 原因及解决
- super() fails with error: TypeError “argument 1 must be type, not classobj”
- TypeError: must be type, not classobj
- Python之Headers value 1 must be of type str or bytes, not <class 'int'>错误的解决
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
- Python 读写文件 错误TypeError: write() argument must be str, not bytes+
- python2.7 使用super关键词 报错 TypeError: must be type, not&n
- 关于python2.7的md5加密遇到的问题(TypeError: Unicode-objects must be encoded before hashing)
- python3-网络编程-TypeError: send() argument 1 must be bytes or buffer, not str异常
- Python TypeError: must be string or buffer, not dict
- Python出现TypeError: file() argument 1 must be encoded string without NULL bytes, not str问题解决
- python错误:TypeError: string indices must be integers