Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling Python 3.3 stdio line termination on windows 7

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?

like image 854
user1981312 Avatar asked Jan 15 '13 18:01

user1981312


1 Answers

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?

like image 84
Eevee Avatar answered Nov 11 '22 07:11

Eevee