Python中super()或object.__new__报TypeError: object.__new__() takes no arguments错误的解决方案
2023-09-27 14:26:59 时间
出现这种情况是调用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__方法参数的困惑
相关文章
- Python 图像数组变换及手绘效果实现
- 25个关键技术点,带你熟悉Python
- python iterable 和list、dictionary的区别和联系
- python学习之调试 错误捕捉及处理
- 第16天:Python 错误和异常
- 解决 Python.h:没有那个文件或目录 错误的方法
- 2021自动化测试Python处理Excel小技巧【温故知新】
- Python错误:AttributeError: 'generator' object has no attribute 'next'解决办法
- Python编程:Django入门及常见错误
- Python 中的 TK编程
- python:dist-packages && site-packages
- [Python]编译错误:编码错误问题(SyntaxError: (unicode error) )
- windows上安装Anaconda和python的教程详解
- python中出现IndentationError:unindent does not match any outer indentation level错误
- Python学习随笔:PyCharm的错误检测使用及调整配置减少错误数量
- Python使用import导入模块时执行了模块的文件但报ModuleNotFoundError错误的愚蠢问题
- Python中import模块时报SyntaxError: (unicode error)'utf-8' codec can't decode 错误的解决办法
- Python中import模块时报SyntaxError: (unicode error)'utf-8' codec can't decode 错误的解决办法
- Python学习笔记之Python对象反射、类反射、模块反射
- 记录python循环引用带来的MemoryError错误解决
- Python pandas.DataFrame.nunique函数方法的使用
- Python连接Mysql数据库——pymysql驱动
- 【Python爬虫错误】ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接
- Python出现UnicodeEncodeError: 'gbk' codec can't encode character 'u22ef' in position 17: ........错误
- 三维点云质心与三角化 — python open3d
- 【错误记录】Python 安装依赖库报错 ( ERROR: Could not find a version that satisfies the requirement elftools )
- 【错误记录】PyCharm 运行 Python 程序报错 ( UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe5 in positio )
- 【错误记录】PyCharm 运行 Python 程序报错 ( SyntaxError: Non-ASCII character ‘xe5‘ in file x.py on line 1, but )
- 【错误记录】Mac 中 IntelliJ IDEA 运行 Python 程序报错 ( “Python“ 因为出现问题而无法打开 )
- 一起调试 Python 和 C++
- Python:什么是赋值与变量
- Python之scrapy的post请求、日志和代理