[ python-Bugs-1305706 ] windows unicode write is messing up the EOL.

SourceForge.net noreply at sourceforge.net
Thu Sep 29 09:54:43 CEST 2005


Bugs item #1305706, was opened at 2005-09-27 13:43
Message generated for change (Comment added) made by visike
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1305706&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Windows
Group: Python 2.4
>Status: Closed
Resolution: None
Priority: 5
Submitted By: Istvan Visegradi (visike)
Assigned to: Nobody/Anonymous (nobody)
Summary: windows unicode write is messing up the EOL.

Initial Comment:
User has an Unicode UTF-16 input file and trys to read
it line-by-line and write it back to a new file.
With the read line the program does nothing.
code example: 
...
ln=fi.readline()
fo.write(ln)
...

In linux this code works perfectly with the input
UTF-16 type file.
In windows Python put an extra \x0D into the EOL.

EOL should look like: 0D 00 0A 00
In windows it will be: 0D 00 0D 0A 00

Please inform when correction is available.

----------------------------------------------------------------------

>Comment By: Istvan Visegradi (visike)
Date: 2005-09-29 10:54

Message:
Logged In: YES 
user_id=1352468

I made the wrong file open without codecs. With codecs it is
opening OK and works correctly. Sorry for my beginners
problem but in the documentation regarding Unicode is not
too clear for me. (I think the problem is probably with me).

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2005-09-27 22:57

Message:
Logged In: YES 
user_id=21627

Can you provide a small test program that demonstrates the
problem?
I cannot reproduce it:

>>> f=codecs.open("f.txt","w",encoding="utf-16")
>>> f.write(u"Hallo\n")
>>> f.write(u"Welt\r\n")
>>> f.close()
>>> open("f.txt").read()
'\xff\xfeH\x00a\x00l\x00l\x00o\x00\n\x00W\x00e\x00l\x00t\x00\r\x00\n\x00'

This looks right to me.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1305706&group_id=5470


More information about the Python-bugs-list mailing list