Python Forum
Class example -i don't understand the error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class example -i don't understand the error
#1
class SuperClass:
    def __init__(self, a1, a2):
        self.attribute1 = a1
        self.attribute2 = a2
    def getAttribute1(self):
        return self.attribute1
    def setAttribute1(self, a1):
        self.attribute1 = a1
    def getAttribute2(self):
        return self.attribute2
    def setAttribute1(self, a2):
        self.attribute2 = a2

class SubClass(SuperClass):
    def getAttribute3(self):
        return self.attribute3
    def setAttribute3(self, a3):
        elf.attribute3 = a3
    def printMessage(self):
        print("My attributes are: ", self.getAttribute1(), \
        self.getAttribute2(), self.getAttribute3())

testObject = SubClass("i", "am", "awesome!")
testObject.printMessage()
and when i run it i get this:
Error:
Traceback (most recent call last): File "/home/main.py", line 23, in <module> testObject = SubClass("Hello", "world", "!!!") TypeError: __init__() takes 3 positional arguments but 4 were given
what is that about?
Reply


Messages In This Thread
Class example -i don't understand the error - by sonedap - Feb-01-2019, 04:24 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020