小编Loo*_*bon的帖子

Python 同步 stdout 和 stderr 输出

使用以下代码:

import sys

print("INFO", flush=True, file=sys.stdout)
print("ERROR", flush=True, file=sys.stderr)
Run Code Online (Sandbox Code Playgroud)

有时输出是:

ERROR
INFO
Run Code Online (Sandbox Code Playgroud)

有时

INFO
ERROR
Run Code Online (Sandbox Code Playgroud)

如何才能让它始终按照代码中编写的顺序打印呢?

printing stdout stderr python-3.x

7
推荐指数
1
解决办法
822
查看次数

标签 统计

printing ×1

python-3.x ×1

stderr ×1

stdout ×1