This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

作者 vstinner
收信人 M..Z., amaury.forgeotdarc, pitrou, vstinner
日期 2011-10-07.09:01:17
SpamBayes Score 7.254196e-08
Marked as misclassified
Message-id <1317978078.78.0.686833741549.issue13119@psf.upfronthosting.co.za>
In-reply-to
内容
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.
历史
日期 用户 动作 参数
2011-10-07 09:01:18vstinner修改recipients: + vstinner, amaury.forgeotdarc, pitrou, M..Z.
2011-10-07 09:01:18vstinner修改messageid: <1317978078.78.0.686833741549.issue13119@psf.upfronthosting.co.za>
2011-10-07 09:01:18vstinner链接issue13119 messages
2011-10-07 09:01:17vstinner创建