STINNER Victor <victor.stin...@haypocalc.com> added the comment:

print() uses PyFile_WriteString("\n", file) by default (if the end argument is 
not set) to write the newline. TextIOWrapper.write("\n") replaces "\n" by 
TextIOWrapper._writenl.

On Windows, stdin, stdout and stderr are creates using TextIOWrapper(..., 
newline=None). In this case, TextIOWrapper._writenl is os.linesep and so '\r\n'.

To sum up, print() writes '\n' into sys.stdout, but sys.stdout write b'\r\n' 
into the file descriptor 1 which is a binary file (ie. the underlying OS file 
doesn't translate newlines).

If the output is redirected (e.g. into a file), TextIOWrapper is created with 
line_buffering=False.

You may try to force line_buffering=True when the output is redirected.

----------
nosy: +pitrou

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13119>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to