有没有办法例如Hello World!每n秒打印一次?例如,程序将遍历我拥有的所有代码,然后经过5秒(带有time.sleep()),它将执行该代码。我将使用它来更新文件,但不打印Hello World。
Hello World
time.sleep()
例如:
startrepeat("print('Hello World')", .01) # Repeats print('Hello World') ever .01 seconds for i in range(5): print(i) >> Hello World! >> 0 >> 1 >> 2 >> Hello World! >> 3 >> Hello World! >> 4
import threading def printit(): threading.Timer(5.0, printit).start() print "Hello, World!" printit() # continue with the rest of your code