[Python-bugs-list] [Bug #122395] readline() of codecs.StreamReader doesn't work for"utf-16le"

noreply@sourceforge.net noreply@sourceforge.net
Tue, 14 Nov 2000 05:37:26 -0800


Bug #122395, was updated on 2000-Nov-14 05:37
Here is a current snapshot of the bug.

Project: Python
Category: Windows
Status: Open
Resolution: None
Bug Group: None
Priority: 5
Summary: readline() of codecs.StreamReader doesn't work for"utf-16le"

Details: I tried that in
BOTH Python 1.6 and Python 2.0
(operating system: Windows NT)

I wrote :

import codecs

fileName1 = "d:\\sveta\\unicode\\try.txt"
(UTF16LE_encode, UTF16LE_decode,
 UTF16LE_streamreader, UTF16LE_streamwriter) = codecs.lookup('UTF-16LE')

output = UTF16LE_streamwriter( open(fileName1, 'wb') )
output.write(unicode('abc\n'))
output.write(unicode('def\n'))
output.close()

input = UTF16LE_streamreader( open(fileName1, 'rb') )
rl = input.readline()
print rl
input.close()

After I run it I got:

Traceback (most recent call last):
  File "d:\\sveta\\unicode\\unicodecheck.py", line 13, in ?
    rl = input.readline()
  File "D:\Program Files\Python16\lib\codecs.py", line 250, in readline
    return self.decode(line)[0]
UnicodeError: UTF-16 decoding error: truncated data

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=122395&group_id=5470