如何在python 2.7.9中使用while循环缓慢打印

时间:2021-11-06 20:55:36

I am trying to print each iteration of the following loop more slowly (so that the person seeing the image printed can actually make out what it is before it goes away too quickly). Any help is welcome. The following code doesn't seem to slow anything down, even when I change the integer to a different number. I don't understand why it's not working.

我试图更慢地打印下一个循环的每个迭代(这样看到打印图像的人实际上可以在它过快消失之前弄清楚它是什么)。欢迎任何帮助。以下代码似乎没有减慢任何速度,即使我将整数更改为不同的数字。我不明白为什么它不起作用。

 import time 
 while True: 

      print  """There are normally 55 lines of strings here, but for readability sake I have deleted them and inserted this text instead."""
 time.sleep(5)

2 个解决方案

#1


wrong indentation it should be

错误的缩进应该是

import time 

while True: 
    print  """There are normally 55 lines of strings here, but for readability sake I have deleted them and inserted this text instead."""
    time.sleep(5)

#2


Because the call to sleep is outside the while loop, you'll run all the prints, and only then sleep the program.

因为对sleep的调用是在while循环之外,所以你将运行所有的打印,然后只是睡眠程序。

Indent the call to sleep to include it in your loop.

缩进调用sleep以将其包含在循环中。

#1


wrong indentation it should be

错误的缩进应该是

import time 

while True: 
    print  """There are normally 55 lines of strings here, but for readability sake I have deleted them and inserted this text instead."""
    time.sleep(5)

#2


Because the call to sleep is outside the while loop, you'll run all the prints, and only then sleep the program.

因为对sleep的调用是在while循环之外,所以你将运行所有的打印,然后只是睡眠程序。

Indent the call to sleep to include it in your loop.

缩进调用sleep以将其包含在循环中。