[Python-Dev] Improve open() to support reading file starting with an unicode BOM

Lennart Regebro regebro at gmail.com
Sun Jan 10 12:21:48 CET 2010

On Sun, Jan 10, 2010 at 12:10, Henning von Bargen
<henning.vonbargen at arcor.de> wrote:
> If Python should support BOM when reading text files,
> it should also be able to *write* such files.

That's what I thought too. Turns out the UTF-16 does write such a
mark. You also have the constants in the codecs module, so you can
write the utf-16-le BOM and then use the utf-16-le encoding if you
want to be sure you write utf-16-le, and the same with BE, of course.

I still think now using BOM's when determining the file format can be
seen as a bug, though, so I don't think the API needs to change at
Lennart Regebro: Python, Zope, Plone, Grok
+33 661 58 14 64

More information about the Python-Dev mailing list