[转载]python中super出现的TypeError: must be type, not classobj 原因及解决
2017-08-25 17:03
666 查看
原文转载自 http://blog.csdn.net/andos/article/details/8973368
示例如下
[python]
view plain
copy
class A():
def __init__(self):pass
class B(A):
def __init__(self):
super(A, self).__init__()
调用B创建对象时出现错误
[plain]
view plain
copy
TypeError: must be type, not classobj
查找资料之后发现,python中super只能应用于新类,而不能应用于经典类
所谓新类就是所有类都必须要有继承的类,如果什么都不想继承,就继承到object类。下面是一个新类的例子
[python]
view plain
copy
class A(B):
....
所谓经典类就是什么都不用继承的类,例如最初的A类就是经典类,下面是一个经典类的例子
[python]
view plain
copy
class A():
....
产上上面的问题,而自己又不知道父类该继承什么,最简单的方法就是让它去继承object类
将class A改为如下
[html]
view plain
copy
class A(object):
.....
则再调用B的实例时,一切正常
示例如下
[python]
view plain
copy
class A():
def __init__(self):pass
class B(A):
def __init__(self):
super(A, self).__init__()
调用B创建对象时出现错误
[plain]
view plain
copy
TypeError: must be type, not classobj
查找资料之后发现,python中super只能应用于新类,而不能应用于经典类
所谓新类就是所有类都必须要有继承的类,如果什么都不想继承,就继承到object类。下面是一个新类的例子
[python]
view plain
copy
class A(B):
....
所谓经典类就是什么都不用继承的类,例如最初的A类就是经典类,下面是一个经典类的例子
[python]
view plain
copy
class A():
....
产上上面的问题,而自己又不知道父类该继承什么,最简单的方法就是让它去继承object类
将class A改为如下
[html]
view plain
copy
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”
- python2.7 使用super关键词 报错 TypeError: must be type, not&n
- 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'>错误的解决
- TypeError: must be type, not classobj
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
- python32版本,出现问题“struct.error: argument for 's' must be a bytes object”的解决办法
- Uncaught TypeError: Super expression must either be null or a function, not undefine
- 快速解决Python问题:TypeError: list indices must be integers or slices, not str
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
- Python 出现错误TypeError: ‘NoneType’ object is not iterable解决办法
- Python 读写文件 错误TypeError: write() argument must be str, not bytes+