Python error TypeError:\uuu init\uuuu()只接受2个参数(给定1个)

2024-05-02 00:28:43 发布

您现在位置:Python中文网/ 问答频道 /正文

在用Python编程时,我遇到了一个错误,需要两个参数,而只有一个。

TypeError: __init__() takes exactly 2 arguments (1 given)

我试过添加额外的参数和其他方法,但我没有找到它的工作参数是类自变量我的代码如下所示。

    import sys, pygame

pygame.init()

size = width, height = 750, 500
backgroundColour = 23, 195, 74

screen = pygame.display.set_mode((size), 0, 32)

class NPC():
    npcList = []

    def GetNPCList(self):
        listNPC = []
        for i in range(0, self.npcList):
            test = self.npcList[i].id
            listNPC.append(test)
        print(listNPC)  


def GetNPC():
    return NPC()

class NPCHandler(object):
    def __init__(self, npcId):
        self.id = id

    def newNPC(self, npcId):
        return NPCHandler(npcId)

    def addNPC(self, n = NPC):
        return n.npcList.append(n)

def GetNPCHandler():
    return NPCHandler()

def main():
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT: 
                sys.exit()

        for i in range(0, 5):
            GetNPCHandler().addNPC(GetNPCHandler().newNPC(1))

        GetNPC().GetNPCList()

        screen.fill(backgroundColour)

        #pygame.draw.circle(screen, (0, 0, 0), (100, 100), 10, 0)

        pygame.display.update()

if __name__ == "__main__":
    main()

Tags: inselfidfor参数returninitdef