How to bypass Windows 'cooking' the I/O? (One more time, please)

Tim Roberts timr at
Fri Jul 4 07:40:32 CEST 2008

norseman <norseman at> wrote:
>Problem:  (sos=same old s...)  Microsoft insists the world work it's way 
>even when the Microsoft way was proven wrong decades ago. In this case 
>it's (still) 'cooking' the writes even with 'rwb' and O_RDWR|O_BINARY in 
>(proper respective) use.

No, it doesn't.  Where did you get the idea that 'rwb' is a valid fopen
mode?  It's not.  If you need to read and write an existing file, you want

Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('x.bat','r+b')
>>> s =
>>> s
'sed -e "s/[ \\t]*$//" -e "/^$/d" %1\rhow about that\r\n'
>>> f.write('xxx\r\n')
>>> f.close()
>>> f = open('x.bat','rb')
>>> t =
>>> t
'sed -e "s/[ \\t]*$//" -e "/^$/d" %1\rhow about that\rxxx\r\n'

>Same python program runs as expected in Linux.  Maybe because that's 
>where it was written?! :)

Perhaps your Linux C runtime library accepts the fopen mode 'rwb', but if
it does, it's a non-standard extension.

>What I seek is the way to slap Microsoft up side the head and make it 
>work correctly.  OK, well, at least in this situation.

It works correctly if you use it correctly.
Tim Roberts, timr at
Providenza & Boekelheide, Inc.

More information about the Python-list mailing list