[Python-bugs-list] [ python-Bugs-768857 ] file readline() mishandles \032 char on Windows

SourceForge.net noreply@sourceforge.net
Thu, 10 Jul 2003 07:03:52 -0700


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

Category: Windows
>Group: Not a Bug
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Mark Bucciarelli (mbucc)
Assigned to: Tim Peters (tim_one)
Summary: file readline() mishandles \032 char on Windows

Initial Comment:
The following snippet behaves differently on Windows (2.2.2) and 
Linux (2.2.1). 
 
>>>s = 'ab\032cd' 
>>>f = file('test', 'w') 
>>>f.write(s+'\n') 
>>>f.close() 
>>>f = file('test') 
>>>f.readline() 
 
Linux returns: 'ab\x1a\cd\n' 
Windows returns: 'ab' 
 
\032 is ascii substitute and also ^z according to this page 
(http://francis.courtois.free.fr/jc1/serial/Resources/ASCII.html). 
 
Thank you. 

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

>Comment By: Tim Peters (tim_one)
Date: 2003-07-10 10:03

Message:
Logged In: YES 
user_id=31435

If you want consistent cross-platform behavior when reading 
or writing binary data, you have to open files in binary mode.  
That is, do not do

f = file('test', 'w')
or
f = file('test')

Instead do

f = file('test', 'wb')
and
f = file('test', 'rb')

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

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