Python计时器倒计时 [英] Python timer countdown
本文介绍了Python计时器倒计时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想了解Python中的计时器。
I want to know about timer in Python.
假设我有一个类似以下代码段:
Suppose i have a code snippet something like:
def abc()
print 'Hi'
print 'Hello'
print 'Hai'
我想每1秒钟打印一次。最多三遍;即;第一秒我需要检查printf,第二秒我也需要检查第三秒。
And i want to print it every 1 second. Max three times;ie; 1st second i need to check the printf, 2nd second I need to check as well in 3rd second.
在我的实际代码变量中,值将被更新。
我需要捕获所有变量的更新时间。
In my actual code variables value will be updated. I need to capture at what second all the variables are getting updated.
有人可以告诉我该怎么做。
Can anybody tell me how to do this.
推荐答案
使用 time.sleep
。
import time
def abc():
print 'Hi'
print 'Hello'
print 'Hai'
for i in xrange(3):
time.sleep(1)
abc()
这篇关于Python计时器倒计时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文