python脚本--单位时间内计时
执行脚本:
python time.py N # N为一个整数,表示时间
time.py
#!/usr/bin/env python from twisted.internet import reactor import time import sys def printTime(): print "Current time is:", time.strftime("%H:%M:%S") for i in range(0, int(sys.argv[1])): reactor.callLater(i, printTime) print 'Running the timeing...' reactor.run()
执行测试下:
root@ubuntu:~# python time.py 6 Running the timeing... Current time is: 17:55:49 Current time is: 17:55:50 Current time is: 17:55:51 Current time is: 17:55:52 Current time is: 17:55:53