当与`os.system`语句混合使用时,`print`函数在Python中不起作用

时间:2019-01-26 10:09:06

标签: python-3.x printf stdout

我有一个程序可以进行大量的数值计算;主循环具有以下形状:

for d in data:
    # compute stuff
    print(current_pattern)
    os.system( external_program_printing_on_stdout + str(current_pattern))

我认为以上变量的名称足以说明它们的内容。

我使用pypy3 script.py | tee log.txt运行程序,但是_I只得到stdout调用中的os.system,而先前的print丢失了。有想法吗?

1 个答案:

答案 0 :(得分:0)

就找到了!

sys.stdout.flush()

(在print函数之后)。

相关问题