# Python 3.0 bug with \r on 64-char boundary in a file encoded using UTF-16* import io, sys encoding = 'utf_16_le' # similar problem with utf_16_be BOM = '\ufeff' for n, odd in ((61,0), (62,1), (62,0)): print(n, odd, file=sys.stderr) raw_bytes = (BOM + 'x' * n + '\r\n' + 'y' * 10 + '\r\n').encode(encoding) + b'z' * odd f = io.TextIOWrapper(io.BytesIO(raw_bytes), encoding='utf16') for lino, line in enumerate(f): print(lino, ascii(line), file=sys.stderr)