为什么当我将 .py 文件转换为基于终端的 .exe 程序时,for 循环中的打印在循环结束之前不会打印?

Why when I convert a .py file to an .exe terminal based program, a print in a for loop isn't printing until the loop has ended?

我想每秒打印一个点 60 次,当我 运行 来自 IDE 的应用程序时,它工作正常但是当我将文件转换为 exe 时,它​​没有打印点直到 for 循环结束。

这是代码:

import time

for i in range(60):
    print(".", end="")
    time.sleep(1) 

对不起,如果这是一个愚蠢的问题,我是 python

的新手

尝试将 flush = True 添加到您的打印功能。

问题可能出在您的程序输出缓冲中,传统上当打印内容达到足够大、出现换行符和退出程序时,它会被刷新。

手动添加flush参数会在每次调用print函数时刷新输出。参见 the print function documentation