我的错误是:

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)相关推荐

  1. TypeError at / __init__() takes exactly 1 argument (2 given)

    完整报错如下: Internal Server Error: /test/ Traceback (most recent call last):   File "/home/appleyuc ...

  2. TypeError: object.__init__() takes no parameters异常报错分析

    from car import Car class Electric(): #这个地方缺少父类名称Cardef __init__(self,makeee,modelll,yearrr,battery ...

  3. 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) ...

  4. Python 3 报错 TypeError: object() takes no parameters【新手必过坑之一】

    在学习 Python 3 类的时候,有如下程序: class Dog():def __init__(self,name,age):#初始化属性name和ageself.name = nameself. ...

  5. Python TypeError: object() takes no parameters

    1.在学习Python中,遇到了一个错误:TypeError: object() takes no parameters,代码如下: class Person():""" ...

  6. 问题TypeError: __init__() takes 1 positional argument but 2 were given解决方案

    问题TypeError: __init__() takes 1 positional argument but 2 were given解决方案 参考文章: (1)问题TypeError: __ini ...

  7. 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 ...

  8. TypeError: __init__() takes 1 positional argument but 2 were given

    在网上阅读了大量的博文.基本上都是因为没有实例化对象而导致的错误.如果没有实例化对象,或者压根就不知道自己有没有实例化对象的小伙伴们可以点击以下博文: Pytorch报错TypeError : ini ...

  9. TypeError: object() takes no parameters

    TypeError: object() takes no parameters 使用类的时候报的错object()不带参数,原因是__init__初始化这个左右各有两个下滑线.

最新文章

  1. 全文检索lucene中文分词的一些总结
  2. solr5.5在centos7上的安装
  3. JSP页面退出时清除会话Session
  4. PAT甲级1001 A+B Format:[C++题解]字符串处理
  5. Linux安装composer出现usr/bin/env: php: No such file or directory)
  6. cdev_init() / cedev_alloc() / cdev_del()
  7. 5gnr帧结构特点有哪些_真空离子束刻蚀设备的结构特点有哪些
  8. 识别图片baidu ai php,PHP+百度AI OCR文字识别实现了图片的文字识别功能
  9. 惊呆了! | Spring Boot 使用 @Value 读取配置还能这样用
  10. Postgre 中的空值判断
  11. python爬虫步骤-Python爬虫的步骤和工具
  12. [转载]让Windows Server 2008 + IIS 7+ ASP.NET 支持10万并发请求
  13. linux如何使用eth0网卡,Linux运维学习之如何取出网卡eth0的ip地址?
  14. java项目中遇到的幂等性问题
  15. C:\Users\xx\.xxxxxx\system\tomcat\xxx\work\Catalina\localhost\ROOT(系统找不到指定文件)
  16. Anaconda下载安装
  17. win7的音量图标不见了
  18. 世唐科技:秒懂什么是区块链
  19. html5锥形,Three.js HTML5 3D开发实例 - 彩色圆锥体
  20. 【jiasuba】分享:键盘失灵烦恼多 教你轻松禁用原键盘

热门文章

  1. 跨境电商未来前景—成都扬帆际海教育咨询有限公司
  2. QMainWindow statusBar如何添加控件
  3. Databricks 第10篇:Job
  4. 在vue项目前端如何实现展示动态小程序二维码
  5. Android Studio 模拟器的加速器 Intel HAXM 的安装及安装失败的原因
  6. SSH HTTPS 公钥、秘钥、对称加密
  7. revit enscape桥梁渲染
  8. 传感器原理及应用复习———光电传感器(精简考试版)
  9. 【视频教程】012.简述with在文件处理中的作用
  10. 本福特定律(Benford‘s law)的直观解释