Skip to content

Commit

Permalink
Problem: tree.show() prints weird characters in the form of \xe2\x94\…
Browse files Browse the repository at this point in the history
…x9c\xe2\x94\x80\xe2\x94\x80

Solution: pass stdout=False to tree.show() to make it return a string and pass that to print()
issue: caesar0301#221
  • Loading branch information
Ahmad Abdolkhani committed Jun 6, 2024
1 parent 7e1daf1 commit 50dd31c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions examples/family_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ def example(desp):
tree = create_family_tree()

example("Tree of the whole family:")
tree.show(key=lambda x: x.tag, reverse=True, line_type="ascii-em")
print(tree.show(key=lambda x: x.tag, reverse=True, stdout=False))

example("All family members in DEPTH mode:")
print(",".join([tree[node].tag for node in tree.expand_tree()]))

example("All family members (with identifiers) but Diane's sub-family:")
tree.show(idhidden=False, filter=lambda x: x.identifier != "diane")
print(tree.show(idhidden=False, filter=lambda x: x.identifier !=
"diane", stdout=False))

example("Let me introduce Diane family only:")
sub_t = tree.subtree("diane")
sub_t.show()
print(sub_t.show(stdout=False))

example("Children of Diane:")
for child in tree.is_branch("diane"):
Expand All @@ -51,15 +52,15 @@ def example(desp):
new_tree.create_node("n2", 2, parent=1)
new_tree.create_node("n3", 3, parent=1)
tree.paste("bill", new_tree)
tree.show()
print(tree.show(stdout=False))

example("They leave after a while:")
tree.remove_node(1)
tree.show()
print(tree.show(stdout=False))

example("Now Mary moves to live with grandfather Harry:")
tree.move_node("mary", "harry")
tree.show()
print(tree.show(stdout=False))

example("A big family for Mark to send message to the oldest Harry:")
print(",".join([tree[node].tag for node in tree.rsearch("mark")]))

0 comments on commit 50dd31c

Please sign in to comment.