Skip Montanaro wrote:
> I am trying to parse some XML which doesn't specify an encoding (Python
> 2.7.12 via Anaconda on RH Linux), so it barfs when it encounters non-ASCII
> data. No great surprise there, but I'm having trouble getting it to use
> another encoding. First, I tried specifying the encoding when opening the
> file:
>
> f = io.open(fname, encoding="utf8")
> root = xml.etree.ElementTree.parse(f).getroot()
>
> but that had no effect.
Isn't UTF-8 the default?
Try opening the file in binary mode then:
with io.open(fname, "rb") as f:
root = xml.tree.ElementTree.parse(f).getroot()
--
https://mail.python.org/mailman/listinfo/python-list