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
#3
When you call SubClass(), that calls the class's __init__ method. Since __init__ is not defined for SubClass, it inherits the one from its parent, SuperClass. The signature for that method is def __init__(self, a1, a2):. The self parameter is automatically supplied by Python, so you only have two parameters left: a1 and a2. You gave three parameters, Python supplied self automatically, so that's four parameters for a method which only has three defined.

For more on classes, check out this tutorial.

BTW, where did you get that code from? It's horrible Python code. You never almost never use getters and setters in Python. They slow things down, make your code harder to understand, and don't actually do anything. If you really need that sort of security (as in, self.y must change whenever self.x changes) you use properties. But generally you just don't bother.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


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

Forum Jump:

User Panel Messages

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