small inconsistency in ElementTree (1.2.6)

Fredrik Lundh fredrik at pythonware.com
Fri Dec 9 02:17:42 EST 2005


Damjan wrote:

> Attached is the smallest test case, that shows that ElementTree returns
> a string object if the text in the tree is only ascii, but returns a unicode
> object otherwise.
>
> This would make sense if the sting object and unicode object were
> interchangeable... but they are not - one example, the translate method
> is completelly different.
>
> I've tested with cElementTree (1.0.2) too, it has the same behaviour.
>
> Any suggestions?

this is documented behaviour.

> Do I need to check the output of ElementTree everytime, or there's some
> hidden switch to change this behaviour?

no.

ascii strings and unicode strings are perfectly interchangable, with some
minor exceptions.  if you find yourself using translate all the time (why?),
add an explicit conversion to the translate code.

(fwiw, I'd say this is a bug in translate rather than in elementtree)

</F>






More information about the Python-list mailing list