How to flush output of print function?

后端 未结 13 1574
旧时难觅i
旧时难觅i 2020-11-21 05:15

How do I force Python\'s print function to output to the screen?

This is not a duplicate of Disable output buffering - the linked question is attempting unbuffe

13条回答
  •  独厮守ぢ
    2020-11-21 05:35

    Also as suggested in this blog one can reopen sys.stdout in unbuffered mode:

    sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
    

    Each stdout.write and print operation will be automatically flushed afterwards.

提交回复
热议问题