How to flush output of print function?

后端 未结 13 1573
旧时难觅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:33

    With Python 3.x the print() function has been extended:

    print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
    

    So, you can just do:

    print("Visiting toilet", flush=True)
    

    Python Docs Entry

提交回复
热议问题