caesar0301 / treelib

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

Dot export crashes when node tag is not a string #52

Closed Miguellissimo closed 5 years ago

Miguellissimo commented 8 years ago

When creating a tree which does not hold string objects the export to the dot file format crashes. See the minimal working example below

import treelib
from treelib.plugins import export_to_dot

t = treelib.Tree()
t.create_node([1,2,3])
export_to_dot(t, 'mwe.dot')
Miguellissimo commented 8 years ago

The problem is caused here. tree[n].tag expects to hold a string which it does not in the code above. I don't know how to get it done across the different python versions but it would be nice to always get the string representation from the object.

caesar0301 commented 8 years ago

You are right. Its an annoying issue to address encoding across python versions. But the problem is more severe. I will fix it later. Thanks

villmow commented 5 years ago

I just stumbled over the same problem, but I wonder why is this a problem across different python versions. To fix it you just need to add str(nid)/ str(cid) while constructing the state and connection.

caesar0301 commented 5 years ago

OK Thanks @villmow

villmow commented 5 years ago

Btw. if your node tag contains quotes, this will produce an invalid dot file. You should escape quotes in the tag before formatting.