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

Treelib not working any longer on Google colab or https://jupyter.org/ #218

Open
mariomuellergermany opened this issue Aug 22, 2023 · 3 comments

Comments

@mariomuellergermany
Copy link

Hi,

I was already using the library and really enjoyed.
But now it is not working any longer.

Im am using the code:

`%pip install treelib
from treelib import Node, 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()

The result is: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'`

Was there an update? Why does it not work any longer?

thanks regards,
Mario

@mariomuellergermany mariomuellergermany changed the title Treelib not working any longer on Google coloab or https://jupyter.org/ Treelib not working any longer on Google colab or https://jupyter.org/ Aug 22, 2023
@realjanpaulus
Copy link

realjanpaulus commented Aug 28, 2023

I had the same problem, it is since this change: 8cd2940 . Something with encoding is weird here.

My current workaround:

# old, both giving the weird encoding
tree.show()
print(tree.show())

# new
print(tree.show(stdout=False))

This bypasses the forced encoding of UTF-8:

treelib/treelib/tree.py

Lines 931 to 934 in 7e1daf1

if stdout:
print(self._reader.encode("utf-8"))
else:
return self._reader

@tomol012
Copy link

Same problem here, although not related Colab or Jupyter in any way. For me it doesn't work in VS Code, Python 3.9.13. I downgraded to 1.6.4 and all is good again.

The workaround from @realjanpaulus is not acceptable to me, because newlines are not displayed in output which means the whole tree is printed as one line, defeating the purpose of the function.

@shaongitbd
Copy link

First save tree using tree.save2file("tree.txt")
then open it using text editor

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

4 participants