gpt4 book ai didi

python - python中的继承错误

转载 作者:太空宇宙 更新时间:2023-11-04 10:23:33 24 4
gpt4 key购买 nike

我正在使用 Pygame 做一个 UNO 游戏,我正在使用卡片列表和每种颜色的类来做,当我试图测试使用颜色类的继承时,我得到了这个错误:

Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
x=example()
File "C:/Users/Tamara/Desktop/TEC/UNO/UNOclases.py", line 93, in __init__
Red.__init__(self,Redlist)
TypeError: unbound method __init__() must be called with Red instance as first argument (got example instance instead)

这是代码(不要介意其中一个名字写错了,我不得不从西类牙语翻译它):

class Red:

def setSpecialRedCards(self):

self.__Redlist.append(self.__steal2)
self.__Redlist.append(self.__steal2)
self.__Redlist.append(self.__Reverse)
self.__Redlist.append(self.__Reverse)
self.__Redlist.append(self.__Jump)
self.__Redlist.append(self.__Jump)

def setRedNumers (self, number,counter):
while counter<=9:
if numero!=0:
self.__Redlist.append(number)
self.__Redlist.append(number)
else:
self.__listaRoja.append(number)
number+=1
counter+=1

def getRed(self):
return self.__Redlist

def __init__(self, Redlist=[]):
self.__Redlist=Redlist
self.__number0 = "red 0"
self.__steal2 = "steal2"
self.__Reverse = "Reverse"
self.__jump = "jump"


class example:

def __init__(self, Redlist=[]):
Red.__init__(self,Redlist)

def example2(self):
return Red.__number0

感谢您的帮助!

最佳答案

您的类 example 没有继承自类 Red

class example(Red):
....

关于python - python中的继承错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30813259/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com