I defined a two classes within one file. I was able to have it run after separating the classes into two files, but I wanted to know why the first attempt does not work.
The traceback read:
Traceback (most recent call last):
File "Polygon.py", line 15, in <module>
class Triangle(Polygon):
File "Polygon.py", line 21, in Triangle
print(self.sides)
NameError: name 'self' is not defined
and the bare bones of my code was as follows
class Polygon:
def __init__(self, no_of_sides):
self.n = no_of_sides
self.sides = [0 for i in range(no_of_sides)]
class Triangle(Polygon):
def __init__(self):
Polygon.__init__(self,3)
It threw the same NameError when I ran this as the body of class Triangle
class Triangle(Polygon):
self.a = 1