How to flush output of print function?

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

    I did it like this in Python 3.4:

    '''To write to screen in real-time'''
    message = lambda x: print(x, flush=True, end="")
    message('I am flushing out now...')
    

提交回复
热议问题