0

在 Windows 上的一些早期 Py3 版本中,我可以通过执行来确保标准输出 LF 而不是 CRLF

import msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
print("Whatever")

但这在某些 Py3.2+ 版本中停止工作。该end='\n'参数也不起作用,所以我猜这是由操作系统或一些低级的东西引起的。在 Py3.3+ 中首选的方法是什么?

4

1 回答 1

0
import sys,os
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', newline='')
print("Whatever")
于 2013-04-24T20:07:55.567 回答