This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author amaury.forgeotdarc
Recipients BreamoreBoy, Richard.Urwin, amaury.forgeotdarc, bugok, effbot, flox, nnorwitz, rurwin
Date 2010-10-02.09:56:27
SpamBayes Score 0.000419802
Marked as misclassified No
Message-id <>
Python 3.1 improves the situation, the file looks more like utf-16, except that the BOM ("\xff\xfe") is repeated all the time, probably on every internal call to file.write().

Here is a test script that should work on both 2.7 and 3.1.

from io import BytesIO
from xml.etree.ElementTree import ElementTree
content = "<?xml version='1.0' encoding='UTF-16'?><html></html>"
input = BytesIO(content.encode('utf-16'))
tree = ElementTree()
# Write content
output = BytesIO()
tree.write(output, encoding="utf-16")
assert output.getvalue().decode('utf-16') == content
Date User Action Args
2010-10-02 09:56:31amaury.forgeotdarcsetrecipients: + amaury.forgeotdarc, effbot, nnorwitz, bugok, rurwin, flox, BreamoreBoy, Richard.Urwin
2010-10-02 09:56:31amaury.forgeotdarcsetmessageid: <>
2010-10-02 09:56:28amaury.forgeotdarclinkissue1767933 messages
2010-10-02 09:56:28amaury.forgeotdarccreate