MINGW64 在执行期间不打印

bod*_*ruk 5 python windows shell console mingw-w64

我正在使用Git Bash在 Windows 上运行我的 Python 脚本。我注意到我的脚本运行时控制台不会打印。当脚本完成时,所有字符串都会被打印出来。我读到这是缓冲区和换行问题。我该如何修复它?

小智 6

我在 Windows10 上使用 MINGW64,并且python -u适用于我。例如,

   python -u foo.py
Run Code Online (Sandbox Code Playgroud)

python --help

-u     : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
         see man page for details on internal buffering relating to '-u'
Run Code Online (Sandbox Code Playgroud)


bod*_*ruk 3

我解决了这个问题,包括sys.stdout.flush()在每个之后print()