How do you write a newline(\n
)-terminated line to stdout under Windows without it being prefixed with a carriage return (\r
)?
For instance, both the following write the 6 characters "line\r\n" to file.txt
python -c "print('line\n', end='')" >file.txt
python -c "import sys; sys.stdout.write('line\n')" >file.txt
Is there not a way to write the 5 characters "line\n" ???
Use of msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) as per Make Python stop emitting a carriage return when writing newlines to sys.stdout doesn't seem to work.
I am using 3.4.4 under Windows 10