Python中super()或object.__new__报TypeError: object.__new__() takes no arguments错误的解决方案
2019-06-25 18:59
896 查看
版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons)
出现这种情况是调用object类__new__方法参数传递多了导致:
一般是使用了类似super().new(cls,*args,**kwargs)
或object.new(self,*args,**kwargs)
这种方式调用的,此时只要改成:
super().new(cls) 或object.new(self)
调用就可以了。
注意:如果直接父类不是object,通过super调用服了的__new__方法,需要看直接父类的参数才知怎么传递参数,因此老猿建议使用object的__new__方法调用。
相关问题请大家参考: Python类中的__new__方法深入剖析:调用父类__new__方法参数的困惑
相关文章推荐
- TypeError: this constructor takes no arguments(Python 学习遇到的错误1)
- type error:this constructor takes no arguments的错误提示(python)
- python调用语音模块报错TypeError:NoneType takes no arguments
- Python 3.5 + PyInstaller 3.2.1打包exe出错,TypeError: read() takes no keyword arguments
- Python3问题TypeError: object() takes no parameters
- __new__方法以及TypeError: object() takes no parameters的处理
- python selenium出现TypeError: __init__() takes 2 positional arguments but 3 were given错误解决方法
- Python中报错提示:TypeError: Student() takes no arguments
- Python开发调用语音模块报错:TypeError:NoneTypetakesnoarguments
- python 编译错误TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
- python机器学习实战3.2提示错误AttributeError: type object 'str' has no attribute '_name_'
- python 使用装饰器提示:TypeError: wrapper() takes no arguments (1 given)
- python:TypeError: this constructor takes no arguments解决方法
- Python_TypeError:object() takes no parameters
- python报错 TypeError: object() takes no parameters
- Python学习之while循环的Ture与False/TypeError: settings() takes no arguments
- python "TypeError: object() takes no parameters"
- 在Python中TypeError: object() takes no parameters新手问题的解决办法
- TypeError: object.__new__() takes no parameters
- python 提示错误AttributeError: type object 'str' has no attribute '_name_'