例如,有没有办法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
https://docs.python.org/3/library/threading.html#timer- objects