Merge pull request #24 from ltworf/fix_print

Fix print
master
Salvo 'LtWorf' Tomaselli 2020-06-18 17:34:36 +07:00 committed by GitHub
commit d3d3c47281
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 6 deletions

@ -121,14 +121,11 @@ class Node:
def printtree(self, level: int = 0) -> str: def printtree(self, level: int = 0) -> str:
'''returns a representation of the tree using indentation''' '''returns a representation of the tree using indentation'''
r = '' r = ' ' * level + self.name
for i in range(level): if self.name in b_operators and isinstance(self, Binary):
r += ' '
r += self.name
if self.name in b_operators:
r += self.left.printtree(level + 1) r += self.left.printtree(level + 1)
r += self.right.printtree(level + 1) r += self.right.printtree(level + 1)
elif self.name in u_operators: elif self.name in u_operators and isinstance(self, Unary):
r += '\t%s\n' % self.prop r += '\t%s\n' % self.prop
r += self.child.printtree(level + 1) r += self.child.printtree(level + 1)
return '\n' + r return '\n' + r