繞進(jìn)去沒繞出來,在死胡同里越繞越深。
出去上了個(gè)廁所,豁然開朗。
不就是想每5分鐘運(yùn)行一個(gè)命令,只允許一次嗎?
繞進(jìn)死胡同的思路
正確的思路:
import timer
import time
import os
while True:
if timer.func(5) is True:
print "Do Something"
time.sleep(60) #直接睡過去一分鐘不就好了嗎?
print time.ctime()[11:-5]
所以說,發(fā)現(xiàn)問題解決不了的時(shí)候要及時(shí)跳開,想想到底想要什么,而不是拘泥于細(xì)節(jié)死扣。
越死扣,越著急,越解決不了。
程序的作用是在00,05,10,15,20,25,30,....這種特定的分鐘跳出循環(huán)執(zhí)行命令。可以用來使重復(fù)采樣實(shí)現(xiàn)。
# Countdown Timer
# Designed By Xc.Li @ Mar.2016
# coding = utf-8
import time
import os
def func(mode):
if mode == 5:
check_point = [00, 05, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]
if mode == 10:
check_point = [00, 10, 20, 30, 40, 50]
if mode == 15:
check_point = [00, 15, 30, 45]
if mode == "test":
check_point = [00, 10, 20, 23]
while True:
current_minute = time.ctime()[14:-8]
for item in check_point:
if str(item) == current_minute or current_minute == '00':
print "Check Point!"
time.sleep(5)
return True
print "Waiting at mode %d" % mode
time.sleep(5)
os.system("cls")