Changed __str__ with __repr__ and vice versa.

parent db709d6c
from node import Leaf
from traverse import traverse_depth_first from traverse import traverse_depth_first
...@@ -183,6 +182,9 @@ def generate_line(root): ...@@ -183,6 +182,9 @@ def generate_line(root):
>>> from node import Node, Leaf >>> from node import Node, Leaf
>>> l0, l1 = Leaf(1), Leaf(2) >>> l0, l1 = Leaf(1), Leaf(2)
>>> print generate_line(l0)
1
>>> plus = Node('+', l0, l1) >>> plus = Node('+', l0, l1)
>>> print generate_line(plus) >>> print generate_line(plus)
1 + 2 1 + 2
......
...@@ -35,6 +35,9 @@ class Node(object): ...@@ -35,6 +35,9 @@ class Node(object):
return '<Node value=%s nodes=%s negated=%d>' \ return '<Node value=%s nodes=%s negated=%d>' \
% (str(self.value), str(self.nodes), self.negated) % (str(self.value), str(self.nodes), self.negated)
def __repr__(self):
return self.__str__()
def title(self): def title(self):
return str(self.value) return str(self.value)
...@@ -49,8 +52,8 @@ class Leaf(Node): ...@@ -49,8 +52,8 @@ class Leaf(Node):
def __len__(self): def __len__(self):
return len(str(self.value)) return len(str(self.value))
def __repr__(self):
return repr('-' * self.negated + str(self.value))
def __str__(self): def __str__(self):
return '<Leaf %s>' % repr(self) return '-' * self.negated + str(self.value)
def __repr__(self):
return '<Leaf %s>' % repr(str(self))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment