I want to know about timer in Python.
Suppose i have a code snippet something like:
def abc()
print 'Hi'
print 'Hello'
print 'Hai'
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.
解决方案
Use time.sleep.
import time
def abc():
print 'Hi'
print 'Hello'
print 'Hai'
for i in xrange(3):
time.sleep(1)
abc()