python延迟执行打印命令? [英] python delayed execution of print command?
问题描述
在我的 python 程序的某些部分,我需要这样做 -
In some part of my python program , I need to do this -
- 在终端上打印一条消息(使用打印命令)
- 创建一些目录(使用 os.mkdirs)
- 复制文件(使用shutil.copy2)
- 再次在终端上显示一条消息(使用打印命令)
(所有这些都在循环中)
(All this is in a loop)
现在的问题是,虽然命令1".在2"之前执行., '3.'和'4.',它实际上显示命令'1'的消息.执行完所有 4 个命令后在屏幕上显示(以及命令 '4.' 的消息).我想要的是它应该显示命令1"的消息.首先,然后从剩下的一段代码开始......我怎样才能做到这一点?(是否也有打印命令的刷新之类的东西?)
Now the problem is, although command '1.' is executed before '2.' , '3.' and '4.', it actually displays the message of command '1.' on the screen after all 4 commands have been executed, (along with the message of command '4.'). What I want is that it should display the message of command '1.' first, then start with the remaining piece of code... How can I make this happen? (Is there something like flushing for the print command as well?)
推荐答案
这可能就是您要找的 如何刷新 Python 打印的输出?
这篇关于python延迟执行打印命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!