opening sys.stdout in binary mode on Windows?

piet at piet at
Thu Oct 18 11:59:53 CEST 2001

>>>>> Bill Janssen <janssen at> (BJ) writes:

BJ> Hi.
BJ> On Windows, I'd like to have stdout opened in binary mode before
BJ> writing to it.  I've tried things like

BJ>    sys.stdout = os.fdopen(sys.stdout.fileno(), "wb")

BJ> without success.  Anyone know the trick?

msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
Piet van Oostrum <piet at>
Private email: P.van.Oostrum at

More information about the Python-list mailing list