treelib
treelib copied to clipboard
Disable sorting per default
Problem: If you call str(tree), it is sorted per default. There is no way of obtaining an unsorted string representation of a tree. The __print_backend function is private and can't be called from outside.
The problem is the the sorting parameter in expand_tree(), which is called by many functions, that don't pass the parameters to expand_tree (to_graphviz, leaves, subtree).
Furthermore the interface to sorting is really messed up (the name of the parameter):
- If you want to iter a tree unsorted you have to call
expand_tree(sorting=False). - You can print a tree unsorted, by calling
tree.show(key=False), - If you want to convert a tree to a dictionary, you need to call
to_dict(sort=True)
I upvote that sorting should be disabled by default. I had a hard time trying to obtain an unsorted tree.show()