8

The following code...

import sys

if sys.platform == "win32":
    import os, msvcrt
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)

sys.stdout.write("This is a sample line of text\n")

...results in the stdio output ending with 0x0d followed by 0x0a. stdio is set to binary mode. Why is the write() call still substituting \r\n for \n?

1 Answers1

1

If you're running this under Cygwin, sys.platform will be 'cygwin' rather than 'win32', but you'll still get line-ending conversion. Are you sure the setmode is actually running?

Eevee
  • 47,412
  • 11
  • 95
  • 127