zoukankan      html  css  js  c++  java
  • Python-TypeError: object() takes no parameters

    Error: TypeError: object() takes no parameters

    Where?

      使用自定义类的时候,实例类的时候传递参数,提示这个错误

    Why?

      因为类实例的时候,并不需要任何参数,但是给了类参数,本质上是类没有 __init__实例方法或者__init__实例方法并没有声明接收任何参数

    Way?

      检查 __init__函数是否写错,init拼写错误或者 __init__函数中是否传递需要初始化的参数

    错误代码:

    class Student(object):
        # init 写错了,写成 int
        def __int__(self, student_list):
            self.student_list = student_list
    
        def __getitem__(self, item):
            return self.student_list[item]
    
    
    students = Student(["beimenchuixue", "北门吹雪"])

    正确代码:

    class Student(object):
        # 把 int 改为 init
        def __init__(self, student_list):
            self.student_list = student_list
    
        def __getitem__(self, item):
            return self.student_list[item]
    
    
    students = Student(["beimenchuixue", "北门吹雪"])
    

      

  • 相关阅读:
    目标检测之YOLOv3
    残差网络(ResNet)
    FPN详解
    YOLOv2/YOLO 9000深入理解
    批归一化(BN)
    全卷积网络FCN
    基于深度学习的目标检测算法综述
    目标检测两个基础部分——backbone and detection head
    YOLOv1 深入理解
    内置模块
  • 原文地址:https://www.cnblogs.com/2bjiujiu/p/9063797.html
Copyright © 2011-2022 走看看