TypeError: object.__new__() takes exactly one argument (the type to instantiate)
我的错误是:
Traceback (most recent call last):
File "D:\anaconda3\envs\pytorch\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 25, in <module>
File "D:\anaconda3\envs\pytorch\lib\typing.py", line 872, in __new__
obj = super().__new__(cls, *args, **kwds)
TypeError: object.__new__() takes exactly one argument (the type to instantiate)
看了几篇文章后发现问题所在,原来是底层文件的写法还是python2,但现在大家都用的是python
3了,python2中定义类的时候__new__()函数是需要返回值的,但是python3不需要了。
我的出错的地方在:
def __new__(cls, *args, **kwds):if cls in (Generic, Protocol):raise TypeError(f"Type {cls.__name__} cannot be instantiated; ""it can be used only as a base class")if super().__new__ is object.__new__ and cls.__init__ is not object.__init__:obj = super().__new__(cls)else:obj = super().__new__(cls, *args, **kwds)#这里出现了返回值return objk
把后面的两个返回值删掉就行
TypeError: object.__new__() takes exactly one argument (the type to instantiate)相关推荐
- TypeError at / __init__() takes exactly 1 argument (2 given)
完整报错如下: Internal Server Error: /test/ Traceback (most recent call last): File "/home/appleyuc ...
- TypeError: object.__init__() takes no parameters异常报错分析
from car import Car class Electric(): #这个地方缺少父类名称Cardef __init__(self,makeee,modelll,yearrr,battery ...
- TypeError: __init__() takes 1 positional argument but 4 were given
执行如下代码的时候报错: import torch import torch.nn as nn N,D_in,H,D_out=64,1000,100,10 x=torch.randn(N,D_in) ...
- Python 3 报错 TypeError: object() takes no parameters【新手必过坑之一】
在学习 Python 3 类的时候,有如下程序: class Dog():def __init__(self,name,age):#初始化属性name和ageself.name = nameself. ...
- Python TypeError: object() takes no parameters
1.在学习Python中,遇到了一个错误:TypeError: object() takes no parameters,代码如下: class Person():""" ...
- 问题TypeError: __init__() takes 1 positional argument but 2 were given解决方案
问题TypeError: __init__() takes 1 positional argument but 2 were given解决方案 参考文章: (1)问题TypeError: __ini ...
- python中function takes exactly_Python error TypeError: function takes exactly 1 argument (5 given)
问题 Traceback (most recent call last): File "wdd.py", line 164, in file.write("tempera ...
- TypeError: __init__() takes 1 positional argument but 2 were given
在网上阅读了大量的博文.基本上都是因为没有实例化对象而导致的错误.如果没有实例化对象,或者压根就不知道自己有没有实例化对象的小伙伴们可以点击以下博文: Pytorch报错TypeError : ini ...
- TypeError: object() takes no parameters
TypeError: object() takes no parameters 使用类的时候报的错object()不带参数,原因是__init__初始化这个左右各有两个下滑线.
最新文章
- 全文检索lucene中文分词的一些总结
- solr5.5在centos7上的安装
- JSP页面退出时清除会话Session
- PAT甲级1001 A+B Format:[C++题解]字符串处理
- Linux安装composer出现usr/bin/env: php: No such file or directory)
- cdev_init() / cedev_alloc() / cdev_del()
- 5gnr帧结构特点有哪些_真空离子束刻蚀设备的结构特点有哪些
- 识别图片baidu ai php,PHP+百度AI OCR文字识别实现了图片的文字识别功能
- 惊呆了! | Spring Boot 使用 @Value 读取配置还能这样用
- Postgre 中的空值判断
- python爬虫步骤-Python爬虫的步骤和工具
- [转载]让Windows Server 2008 + IIS 7+ ASP.NET 支持10万并发请求
- linux如何使用eth0网卡,Linux运维学习之如何取出网卡eth0的ip地址?
- java项目中遇到的幂等性问题
- C:\Users\xx\.xxxxxx\system\tomcat\xxx\work\Catalina\localhost\ROOT(系统找不到指定文件)
- Anaconda下载安装
- win7的音量图标不见了
- 世唐科技:秒懂什么是区块链
- html5锥形,Three.js HTML5 3D开发实例 - 彩色圆锥体
- 【jiasuba】分享:键盘失灵烦恼多 教你轻松禁用原键盘