Error with inheritance in python

77 Views Asked by At

i'm doing an UNO game using Pygame, i'm doing it with lists of cards and classes of each color, when I tried to test the inheritance for using the color class, I got this error:

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)

Here's the code (don't mind if one of the names is wrong written, I had to translate it from spanish):

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

Thank you for your help!

1

There are 1 best solutions below

2
On BEST ANSWER

Your class example doesn't inherit from class Red.

Write

class example(Red):
    ....