2014-02-20 190 views
0

请告诉我如何确保函数printit()每秒执行一次?每x秒运行一次代码

import threading 

def printit(): 
    print("Hello, World!")  

threading.Timer(1.0, printit).start() 

的问题是, '世界你好' 只出现一次

+0

也:http://stackoverflow.com/questions/510348/how-can-i/-make-A-延时功能于蟒510351#510351 –

回答

2

如何

import time 
while True: 
    time.sleep(1) 
    print ('Hello world')