[New-bugs-announce] [issue18268] ElementTree.fromstring non-deterministically gives unicode text data
report at bugs.python.org
Wed Jun 19 23:21:54 CEST 2013
New submission from Brendan O'Connor:
(This is Python 2.7 so I'm using string vs unicode terminology.)
When I use ElementTree.fromstring(), and use the .text field on nodes, the value is usually a string object, but in rare cases it's a unicode object. I'm parsing many XML documents of newspaper text ; on one subset of the data, out of 5 million nodes, ~200 of them have a unicode object for the .text field.
I think this is all related to http://bugs.python.org/issue11033 but I can't figure out how, exactly. I'm passing in strings to ElementTree.fromstring() like you're supposed to.
The workaround is to defensively convert the .text value to unicode .
 data is http://www.ldc.upenn.edu/Catalog/catalogEntry.jsp?catalogId=LDC2012T21
 my processing code is https://github.com/brendano/gigaword_conversion/blob/master/annogw2justsent.py
if isinstance(mystr, unicode):
if isinstance(mystr, str):
title: ElementTree.fromstring non-deterministically gives unicode text data
versions: Python 2.7
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce