python print function in real time

后端 未结 3 1868
粉色の甜心
粉色の甜心 2020-12-06 05:51

I recently switched OS and am using a newer Python (2.7). On my old system, I used to be able to print instantaneously. For instance, suppose I had a computationally intense

3条回答
  •  佛祖请我去吃肉
    2020-12-06 06:26

    Try to call flush of stdout after the print

    import sys
    
    ...
    sys.stdout.flush()
    

    Or use a command line option -u which:

    Force stdin, stdout and stderr to be totally unbuffered.

提交回复
热议问题