Python 调用super初始化报错 "super() argument 1 must be type, not classobj"
来源:互联网 发布:贪玩传奇盛世翅膀数据 编辑:程序博客网 时间:2024/06/05 12:38
python3.0不存在,旧版本可能报错:
class A(): def __init__(self): print('A')class B(): def __init__(self): print('B')class C(): def __init__(self): print('C')class Asub(A): def __init__(self): print('Asub') super(Asub, self).__init__()class Bsub(B): def __init__(self): print('Bsub') super(Bsub,self).__init__()class Csub(C): def __init__(self): print('Csub') super(Csub, self).__init__()class E(Asub, Bsub, Csub): def __init__(self): print ('E') Asub.__init__(self) Bsub.__init__(self) Csub.__init__(self)d = E()
在子类Asub中调用super初始化时发生错误:其中A为超类,仔细检查并无语法错误。 super(Asub, self).init() TypeError: super() argument 1 must be type, not classobj 原因如下: 在python2.2版本之前,直接调用超类的方法,后来改成通过super来调用,原因是为了解决多重继承中的钻石形状问题。python里的super只能用在新式类中,不能用于以前的经典类,如果基类是经典类则会出现这个错误。 解决的方法是Asub只要有一个超类是Object就OK了。 例如: A(object):…………….
class A(object):#!!!!!!!based in object!!!!!! def __init__(self): print('A')class B(object): def __init__(self): print('B')class C(object): def __init__(self): print('C')class Asub(A): def __init__(self): print('Asub') super(Asub, self).__init__()class Bsub(B): def __init__(self): print('Bsub') super(Bsub,self).__init__()class Csub(C): def __init__(self): print('Csub') super(Csub, self).__init__()class E(Asub, Bsub, Csub): def __init__(self): print ('E') Asub.__init__(self) Bsub.__init__(self) Csub.__init__(self)d = E()
注意:构造类的时候,习惯性继承基类object!!!
阅读全文
0 0
- Python 调用super初始化报错 "super() argument 1 must be type, not classobj"
- Python 调用super初始化报错 "super() argument 1 must be type, not classobj"
- super() fails with error: TypeError “argument 1 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 原因及解决
- python中super()出现的TypeError: must be type, not classobj
- [转载]python中super出现的TypeError: must be type, not classobj 原因及解决
- python 调用super()初始化报错“TypeError: super() takes at least 1 argument”
- python 调用super()初始化报错“TypeError: super() takes at least 1 argument”
- TypeError: must be type, not classobj
- python-TypeError: write() argument must be str, not numpy.float64
- TypeError: super(type, obj): obj must be an instance or subtype of type
- Python出现TypeError: file() argument 1 must be encoded string without NULL bytes, not str问题解决
- TypeError: argument 1 must be string or buffer, not instance
- Content-Type为null报 'mediatype' must not be empty错
- 报错解决Argument 1 passed to model::get***() must be an instance of Entity_hotel, instance
- Android事件机制之一:事件传递和消费
- 错误中学习--Connections could not be acquired from the underlying database
- 样本方差的无偏估计与(n-1)的由来
- MySQL数据库InnoDB存储引擎Log漫游(1)
- Linux下搜索字符串命令
- Python 调用super初始化报错 "super() argument 1 must be type, not classobj"
- 启动tomcat时奇怪的端口占用
- Failed to recognize predicate 'xxx'. Failed rule: 'identifier' in column specification
- C. The Tag Game
- [java] 块语句内不能加访问修饰符
- OWASP的WebScarab简介
- DATE类型的加减
- 怎么将maven项目打包成war包
- mysql数据库中“0000-00-00 00:00:00”格式无法转换成datatime类型的问题解决方法