ESSAY / NOTE

python time.sleep print缓存

当您使用python 3时,可以使用flush = True 方法1 for i in range(50): sleep(0.1) print("#", end = '', flush=True) 输出到文件 import time import sys f = open("out.txt", "a+") # print('GO', file = f) while True: print('GO', file = f,flush=True) time.sleep(1) 方法2 您可以-u在运行程序时使用该选项。 python3 -u file.py 原文 https://stackoverflow.com/questions/56896710/does-time-sleep-not-work-inside-a-for-loop-with-a-print-function-using-the