Message 110252 - Python tracker (original) (raw)
In xml.etree, ElementTree and cElementTree implement different interfaces for the iterparse function/class.
In ElementTree, the argument "events" must be a tuple of strings:
from xml.etree import ElementTree as ET for result in ET.iterparse('example.xml', events=('start', 'end')): print(result)
That works, given a valid XML file 'example.xml'. If the event names are given as bytes instead of strings (b'start', b'end'), there's no crash, but no events are recognized.
In cElementTree, it's the opposite: the events argument must be a tuple of bytes:
from xml.etree import cElementTree as cET for result in cET.iterparse('example.xml', events=(b'start', b'end')): print(result)
Giving a tuple of strings instead of bytes results in:
for result in cET.iterparse('example.xml', events=('start', 'end')): ... print(result) TypeError: invalid event tuple
This makes it difficult to use ElementTree as a backup for cElementTree, or at least very awkward.