caesar0301 / treelib

An efficient implementation of tree data structure in python 2/3.
http://treelib.readthedocs.io/en/latest/
Other
812 stars 186 forks source link

Tree.__str__() #42

Closed suizokukan closed 9 years ago

suizokukan commented 9 years ago

Since I think it's convenient that every Python object may be introspected with its str() method, I suggest adding such a method to the Tree class. The suggested Tree.str() method simply returns what is "drawn" by Tree._print_backend(). The code seems ok with Python2/3; the tests are ok with Python3.

o added Tree.str() method, by simply returning the value returned by Tree._print_backend(). o since str() in Python2 doesn't have to return non-unicode characters, I used a trick found in Django's code, a decorator above the Tree class. (see http://django.readthedocs.org/en/latest/_modules/django/utils/encoding.html) o modified TestCase.test_print_backend() by using the str() method.

caesar0301 commented 9 years ago

It seems that there are compatible errors with Python 2 reported by Travis CI (https://travis-ci.org/caesar0301/treelib). Could you please fix it and let me merge this feature directly?

suizokukan commented 9 years ago

Yes, I'm working on it. I hope to fix the problem as soon as possible.

suizokukan commented 9 years ago

Everything's fine but I'm not very proud of the way I fixed the problem.