Bug with win32 open and utf-16 file

derek / nul abuseonly at sgrail.org
Sat Aug 23 16:36:58 CEST 2003


HI all,

I appear to have found a bug with win32 open and utf-16 files.

utf-16 file available at www.sgrail.org/files/dash9.eng

the program
-----------------------------------------------------------------------------------
#!c:/program files/python/python.exe
# win32 python 2.3

import sys, string, codecs
#eng_file = list (open("c:/program files/microsoft games/train
simulator/trains/trainset/dash9/dash9.eng", "rb").read())	# read the whole file
eng_file = open("c:/program files/microsoft games/train
simulator/trains/trainset/dash9/dash9.eng", "rb").read()	# read the whole file

print hexdump (eng_file)						# ok
-------------------------------------------------------------------------------------------

The original file has line terminator characters of 00 0d 00 0a.
After being read into a variable or a list the line termination characters have
been changed to 00 0a 00 0a

hex dump after open

$00000000 FFFE5300 49004D00 49005300 41004000 40004000  ..S.I.M.I.S.A.......
$00000014 40004000 40004000 40004000 40004A00 49004E00  ..............J.I.N.
$00000028 58003000 44003000 74005F00 5F005F00 5F005F00  X.0.D.0.t...........
$0000003C 5F000A00 0A000A00 0A00

Any comments?
Derek





More information about the Python-list mailing list