python中super出现的TypeError: must be type, not classobj 原因及解决
2013-05-25 14:23
976 查看
示例如下
调用B创建对象时出现错误
查找资料之后发现,python中super只能应用于新类,而不能应用于经典类
所谓新类就是所有类都必须要有继承的类,如果什么都不想继承,就继承到object类。下面是一个新类的例子
所谓经典类就是什么都不用继承的类,例如最初的A类就是经典类,下面是一个经典类的例子
产上上面的问题,而自己又不知道父类该继承什么,最简单的方法就是让它去继承object类
将class A改为如下
则再调用B的实例时,一切正常
class A(): def __init__(self):pass class B(A): def __init__(self): super(A, self).__init__()
调用B创建对象时出现错误
TypeError: must be type, not classobj
查找资料之后发现,python中super只能应用于新类,而不能应用于经典类
所谓新类就是所有类都必须要有继承的类,如果什么都不想继承,就继承到object类。下面是一个新类的例子
class A(B): ....
所谓经典类就是什么都不用继承的类,例如最初的A类就是经典类,下面是一个经典类的例子
class A(): ....
产上上面的问题,而自己又不知道父类该继承什么,最简单的方法就是让它去继承object类
将class A改为如下
class A(object): .....
则再调用B的实例时,一切正常
相关文章推荐
- [转载]python中super出现的TypeError: must be type, not classobj 原因及解决
- python中super出现的TypeError: must be type, not classobj 原因及解决
- python中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 解决办法
- python2.7 使用super关键词 报错 TypeError: must be type, not classobj 解决办法
- python中super()出现的TypeError: must be type, not classobj
- python:TypeError: must be type, not classobj
- super() fails with error: TypeError “argument 1 must be type, not classobj”
- Python出现TypeError: file() argument 1 must be encoded string without NULL bytes, not str问题解决
- Python之Headers value 1 must be of type str or bytes, not <class 'int'>错误的解决
- python2.7 使用super关键词 报错 TypeError: must be type, not&n
- TypeError: must be type, not classobj
- Python错误解决 TypeError: first arg must be callable
- MPI编译C++程序出现#error "SEEK_SET is #defined but must not be for the C++ binding of MPI" 的解决方法
- MPI编译C++程序出现#error "SEEK_SET is #defined but must not be for the C++ binding of MPI" 的解决方法
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
- Python 读写文件 错误TypeError: write() argument must be str, not bytes+
- 快速解决Python问题:TypeError: list indices must be integers or slices, not str
- Uncaught TypeError: Super expression must either be null or a function, not undefine