简体   繁体   English

python延迟执行打印命令?

[英]python delayed execution of print command?

In some part of my python program , I need to do this - 在我的python程序的某些部分,我需要这样做-

  1. print a message on the terminal (using the print command) 在终端上打印一条消息(使用打印命令)
  2. make some directories (using os.mkdirs) 制作一些目录(使用os.mkdirs)
  3. copy a file (using shutil.copy2) 复制文件(使用shutil.copy2)
  4. Again display a message on terminal (using the print command) 再次在终端上显示一条消息(使用打印命令)

(All this is in a loop) (所有这些都是循环的)

Now the problem is, although command '1.' 现在的问题是,尽管命令为“ 1”。 is executed before '2.' 在“ 2”之前执行。 , '3.' ,“ 3”。 and '4.', it actually displays the message of command '1.' 和“ 4”,它实际上显示命令“ 1”的消息。 on the screen after all 4 commands have been executed, (along with the message of command '4.'). 在执行完所有4条命令后(在屏幕上显示命令4)。 What I want is that it should display the message of command '1.' 我想要的是它应该显示命令“ 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打印输出?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM