To practice python, I made a simple class for a tree structure in which each node can have infinite child nodes.
class Tree():
def __init__(self, children, val):
self.children = children
self.val = val
def add(self, child):
self.children.append(child)
def remove(self, index):
child = self.children[index]
self.children.remove(child)
return child
def print(self):
self.__print__(0)
def __print__(self, indentation):
valstr = ''
for i in range(0, indentation):
valstr += ' '
valstr += self.val
for child in self.children:
child.__print__(indentation + 1)
However, I have a syntax error in the line def print(self):
. Where is the error? I have been looking for a long time, and it seems like the right way to define a python function.
I have also tried
@override
def print(self):
self.__print__(0)
to no avail.