python中super出现的TypeError: must be type, not classobj 原因及解决
2016-09-11 20:16
741 查看
执行一下代码,出现错误,TypeError: must be type, not classobj
class A():
def __init__(self):
print("Enter A")
print("Leave A")
class B(A):
def __init__(self):
print("Enter B")
super(B, self).__init__()
print("Leave B")
class C(A):
def __init__(self):
print("Enter C")
super(C, self).__init__()
print("Leave C")
class D(A):
def __init__(self):
print("Enter D")
super(D, self).__init__()
print("Leave D")
class E(B, C, D):
def __init__(self):
print("Enter E")
super(E, self).__init__()
print("Leave E")
E()
输出错误:
Traceback (most recent call last):
File "F:/test5.py", line 35, in <module>
E()
File "F:/test5.py", line 32, in __init__
super(E, self).__init__()
TypeError: must be type, not classobj
百度之后发现,python中super只能应用于新类,而不能应用于经典类
见:http://blog.csdn.net/andos/article/details/8973368
使用新式类(即A继承自object)后正常。
class A():
def __init__(self):
print("Enter A")
print("Leave A")
class B(A):
def __init__(self):
print("Enter B")
super(B, self).__init__()
print("Leave B")
class C(A):
def __init__(self):
print("Enter C")
super(C, self).__init__()
print("Leave C")
class D(A):
def __init__(self):
print("Enter D")
super(D, self).__init__()
print("Leave D")
class E(B, C, D):
def __init__(self):
print("Enter E")
super(E, self).__init__()
print("Leave E")
E()
输出错误:
Traceback (most recent call last):
File "F:/test5.py", line 35, in <module>
E()
File "F:/test5.py", line 32, in __init__
super(E, self).__init__()
TypeError: must be type, not classobj
百度之后发现,python中super只能应用于新类,而不能应用于经典类
见:http://blog.csdn.net/andos/article/details/8973368
使用新式类(即A继承自object)后正常。
相关文章推荐
- 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 解决办法
- python2.7 使用super关键词 报错 TypeError: must be type, not classobj 解决办法
- python中super()出现的TypeError: must be type, not classobj
- python出现super.__init__: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: ‘NoneType’ object is not iterable解决办法
- MPI编译C++程序出现#error "SEEK_SET is #defined but must not be for the C++ binding of MPI" 的解决方法
- python32版本,出现问题“struct.error: argument for 's' must be a bytes object”的解决办法
- Python错误解决 TypeError: first arg must be callable
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
- 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+