Feb. 21, 2012
7:29 a.m.
Simon Sapin wrote:
Le 21/02/2012 06:52, Frank Millman a écrit :
a = etree.fromstring(b'<?xml version="1.0" encoding="UTF-8"?><root><child>da ta\u00e7</child></root>') a[0].text 'data\\u00e7'
The \uHHHH escaping is not allowed in Python 3 byte strings, so your XML source contains a backslash, then the letter u, etc. You see that the backslash is doubled (escaped) in your output.
a = etree.fromstring('<?xml version="1.0"?><root><child>data\u00e7</child></ root>')
>> a[0].text 'dataç'
Here the XML source is completely different (regardless of type/encoding) and contains an actual ç. If you want it escaped in a Python literal of utf8 bytes, try \xc3\xa7.
Doh! Of course. Thank you, Simon. Frank