Closed Natim closed 9 years ago
Oh: https://github.com/caesar0301/pyTree/blob/master/treelib/node.py#L33
Why are you using str instead of six.string_types ?
Hi Natim, I am not really familiar with that library, six.*. I made the node ID as string and integer with the thought to be simple and stable. Thanks for your reminding. So what is ur need, unicode type string as ID?
Jamin
Actually the biggest change between Py2 and Py3 is about that string type.
Basically, six is just a library with some tools that helps speaking the same language between Py2 and Py3.
Some people doesn't use six, but add a _compat.py file that take from six what is needed for the project.
In that case, prior to treelib==1.2.5, identifier could be a str or an unicode and in Py3 we want it to be a str() (because there is no more unicode)
Six code about string_types : https://bitbucket.org/gutworth/six/src/e25ad0ad989b59fe1e6b91ecf21adfa217f66c6e/six.py?at=default
Example of _compat.py file in mitsuhiko projects: https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/ _compat.py
I guess I have this issue as well. I'm trying to use a tuple, e.g (0,'hi') as identifier but get the "Only string and integer types are supported currently" exception. On what conditions it might be considered as string? And how can it be fixed?
My Python version is 2.7.3.
Thanks.
You can use '-'.join(tuple)
to build your idenfiier.
I know this is kind of solutions, but I want to understand the root of the problem. Is it an issue of Python 2 and 3 versions? On what versions it should work fine?
Yes I supposed it is the same question as for tag property. Why do we need to force it? Python is working with object, so we should allow any object for _identifier as for tag I guess.
I think I agree. I don't see any reason for identifier to be forced to be an int or a string especially when the function sanitize_id doesn't do anything, but check for int or string.
I think we should add some tests about all this to prevent any problem later on.
I am also thinking about an object-based identifier, as you suggested. But it may not be a good way to use python build-in object reference to identify a node, because the user needs to trace the original object when referring to a node.
The eq method of class instance may helps us about this. But is there any potential instability about this?
Jamin
Unicode is not string anymore in python2