Hi there,
I have two files "my.utf8" and "my.utf16" which
both contain BOM and two "a" characters.
Contents of "my.utf8" in HEX:
EFBBBF6161
Contents of "my.utf16" in HEX:
FEFF6161
For some reason Python2.4 decodes the BOM for UTF8
but not for UTF16. See below:
[color=blue][color=green][color=darkred]
>>> fh = codecs.open("my .uft8", "rb", "utf8")
>>> fh.readlines()[/color][/color][/color]
[u'\ufeffaa'] # BOM is decoded, why[color=blue][color=green][color=darkred]
>>> fh.close()
>>> fh = codecs.open("my .utf16", "rb", "utf16")
>>> fh.readlines()[/color][/color][/color]
[u'\u6161'] # No BOM here[color=blue][color=green][color=darkred]
>>> fh.close()[/color][/color][/color]
Is there a trick to read UTF8 encoded file with BOM not decoded?
-pekka-
I have two files "my.utf8" and "my.utf16" which
both contain BOM and two "a" characters.
Contents of "my.utf8" in HEX:
EFBBBF6161
Contents of "my.utf16" in HEX:
FEFF6161
For some reason Python2.4 decodes the BOM for UTF8
but not for UTF16. See below:
[color=blue][color=green][color=darkred]
>>> fh = codecs.open("my .uft8", "rb", "utf8")
>>> fh.readlines()[/color][/color][/color]
[u'\ufeffaa'] # BOM is decoded, why[color=blue][color=green][color=darkred]
>>> fh.close()
>>> fh = codecs.open("my .utf16", "rb", "utf16")
>>> fh.readlines()[/color][/color][/color]
[u'\u6161'] # No BOM here[color=blue][color=green][color=darkred]
>>> fh.close()[/color][/color][/color]
Is there a trick to read UTF8 encoded file with BOM not decoded?
-pekka-
Comment