TypeError: must be type, not classobj
2016-11-02 23:04
465 查看
__metaclass = type;
class T(): def __init__(self): pass; class G(T): def __init__(self): super(G, self).__init__();
m =G(); 报错TypeError: must be type, not classobj
这里就涉及到了新式类和旧式类的问题,也有人教经典类和新类.
在使用super的时只有在新式类中有效,如何申明新式类?
第一:加__metaclass = type;
第二:所有的类都要有超类,如果没有超类,那么就继承object.所有可以将T改为这样:
class T(object):
#code here
这样再实例化G的时候就不会报TypeError: must be type, not classobj错误了
相关文章推荐
- python: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 原因及解决
- 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 原因及解决
- super() fails with error: TypeError “argument 1 must be type, not classobj”
- python出现super.__init__:TypeError:must be type,not classobj
- python中super()出现的TypeError: must be type, not classobj
- Python 读写文件 错误TypeError: write() argument must be str, not bytes+
- [bug] captcha中demo运行失败(TypeError must be sequence of length 4, not 2)
- Uncaught TypeError: Super expression must either be null or a function, not undefine
- python2.7 使用super关键词 报错 TypeError: must be type, not&n
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
- Python之Headers value 1 must be of type str or bytes, not <class 'int'>错误的解决
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
- TypeError: unbound method must be called with class instance 1st argument
- TypeError: name must be an instance of basestring
- TypeError: Path must be a string. Received undefined