在 sikulix 中,如何在倒计时结束后不会重复的情况下进行 while 循环?



我想做一个while循环,在指定时间后不会重复。顺便说一句,我不是一个程序员,谢谢你的理解。

我被要求扩展我的答案,所以我会添加注释来解释每一行。此外,这个答案不是sikuli特有的,可以用于任何python/jython代码。

# import time module
import time           
# define how many seconds loop will last
loopForSeconds = 30   
# get current time in seconds since epoch
t0 = time.time()      
# loop while time delta is less than required (30 seconds in this example)
while time.time()-t0 < loopForSeconds:    

# do something in the loop    
print "This will repeat for 30 seconds"

# you may want to slow down your loop by adding some sleep time
# in this case add 1 second to slow down the loop
# so there will be about 30 loops for 30 seconds
# depends on other commands in the loop
time.sleep(1)

最新更新