Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 该类只接受1个参数,但给出了4个参数_Python_Python 3.x_Oop - Fatal编程技术网

Python 该类只接受1个参数,但给出了4个参数

Python 该类只接受1个参数,但给出了4个参数,python,python-3.x,oop,Python,Python 3.x,Oop,我不断得到以下错误: TypeError: PetLog() takes 1 positional argument but 4 were given 当我运行此命令时: pet_1 = ShelterPets('shelby', 'poodle', 'medium sized and white', df) 我的代码是: def ShelterPets(PetLog): def __init__( self, pet_name: str,

我不断得到以下错误:

TypeError: PetLog() takes 1 positional argument but 4 were given
当我运行此命令时:

pet_1 = ShelterPets('shelby', 'poodle', 'medium sized and white', df)
我的代码是:

def ShelterPets(PetLog):
    def __init__(
        self, 
        pet_name: str, 
        pet_breed: str,
        description: str,
        pet_dataframe
    ):

        super().__init__(
            pet_name=pet_name,
            pet_adoption='shelter',
            pet_breed=pet_breed,
            description=description,
            pet_dataframe=pet_dataframe
        )
        
    def pet_codes(self):
        pet_code_list = self.pet_dataframe['pet_code'].tolist()
        self.pet_code_id = pet_code_list
这是它继承的父类:

from abc import ABC, abstractmethod


class PetLog(ABC):
    def __init__(
        self,
        pet_name: str,
        pet_adoption: str, 
        pet_breed: str,
        description: str,
        pet_dataframe
    ):

        self.pet_name = pet_name
        self.pet_adoption = pet_adoption
        self.pet_breed = pet_breed
        self.description = description
        self.pet_dataframe = pet_dataframe
        
        self.pet_code_id = None
        
    @abstractmethod
    def pet_codes(self):
        pass

    @abstractmethod
    def pet_food(self):
        pass


我已经检查了缩进是否正确,语法是否正确,还检查了所有内容是否按正确的顺序排列。任何帮助都将不胜感激。

@user202729这是一个内置模块,允许我使用您试图使用
def
声明类的抽象类方法。@Selcuk您能澄清一下吗?谢谢你的
def ShelterPets(PetLog):
行应该是
class ShelterPets(PetLog):
@Selcuk噢,哇,谢谢你!我认为当你盯着代码看太久的时候就会发生这种情况