treelib
treelib copied to clipboard
tree.show prints binary literal to stdout
Issue #82 seems to have been reintroduced at some point after release 1.3.2:
from treelib import Tree
tree = Tree()
tree.create_node("Harry", "harry") # root node
tree.create_node("Jane", "jane", parent="harry")
tree.create_node("Bill", "bill", parent="harry")
tree.create_node("Diane", "diane", parent="jane")
tree.create_node("Mary", "mary", parent="diane")
tree.create_node("Mark", "mark", parent="jane")
tree.show()
results in:
b'Harry\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Bill\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Jane\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Diane\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Mary\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Mark\n'
Also encountered this issue.
As a temporary workaround I changed this line:
print(self._reader.encode("utf-8"))
To:
print(self._reader)
In virtual environment it was in .venv/lib/python3.11/site-packages/treelib/tree.py
on line 932.
I'm also affected by this bug. Thanks @lab-Brat for the workaround.
There's no need to need to patch the module as a workaround. tree.show() does return the output as a string when told not to write to stdout. So just do that as an argument to print:
print(tree.show(stdout=False))
Keep pythons utf-8 handling in mind though. You might want to set the output encoding to utf-8 due to that.
I have this problem, too. Fedora 40, Gnome 46, Python 3.11 in virtual environment