repr
on a string gives quotes while str
does not. e.g.:
>>> s = 'foo'
>>> print str(s)
foo
>>> print repr(s)
'foo'
Try:
def __repr__(self):
if len(self.children) == 0:
return '%s' %self.value
else:
childrenStr = ' '.join(map(str, self.children)) #str, not repr!
return '(%s %s)' % (self.value, childrenStr)
instead.