Stefan Behnel wrote:
With Python 3 and version 2.3.3, if you pass a unicode string to etree.fromstring(...), and then retrieve a text node from
the tree, you get
a unicode string back. If you pass in a byte array, you get a byte array back.
No, you always get a Unicode string for names and text in Python 3, regardless of what you used for parsing (or tree building in general).
You are right - sorry about that. I got confused by the following -
a = etree.fromstring(b'<?xml version="1.0" encoding="UTF-8"?><root><child>da ta\u00e7</child></root>') a[0].text 'data\\u00e7' a = etree.fromstring('<?xml version="1.0"?><root><child>data\u00e7</child></ root>') a[0].text 'dataƧ'
In the first case I pass in a byte array, and the text node is displayed in my terminal (Windows Command Prompt) with the unicode character escaped. In the second case I pass in a unicode string and the resulting unicode character is displayed normally. As you say, they are both unicode strings. I don't know why they display differently. Frank