Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree.show prints binary literal to stdout #221

Open
aholten opened this issue Nov 28, 2023 · 4 comments
Open

tree.show prints binary literal to stdout #221

aholten opened this issue Nov 28, 2023 · 4 comments

Comments

@aholten
Copy link

aholten commented Nov 28, 2023

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'

@Lab-Brat
Copy link

Lab-Brat commented Dec 2, 2023

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.

@sylock
Copy link

sylock commented Jan 8, 2024

I'm also affected by this bug. Thanks @Lab-Brat for the workaround.

@3add3287
Copy link

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.

tom-mi added a commit to tom-mi/aws-ssm-tree that referenced this issue Feb 13, 2024
- At least on Python 3, instead of a nicely formatted tree the former
  command showed a byte string (b'...').
- See also caesar0301/treelib#221
@SoundDesignerToBe
Copy link

SoundDesignerToBe commented May 29, 2024

I have this problem, too. Fedora 40, Gnome 46, Python 3.11 in virtual environment

ahmad-abdolkhani pushed a commit to ahmad-abdolkhani/treelib that referenced this issue Jun 6, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants