我想让函数在每小时的最高峰开始(python)
我有一个函数我想让函数在每小时的最高峰开始(python),python,python-2.7,Python,Python 2.7,我有一个函数hello\u world(),我想每小时(1:00、2:00、3:00等)调用一次 我是这里的初学者,不太习惯写循环 我有下面的代码,但它会在23小时后停止。我不知道如何循环,使每件事都在一天结束时重复 def sched (): i = 0 for (i <= 23): x = datetime.today() current_hour = datetime.now().hour y=x.replace(d
hello\u world()
,我想每小时(1:00、2:00、3:00等)调用一次
我是这里的初学者,不太习惯写循环
我有下面的代码,但它会在23小时后停止。我不知道如何循环,使每件事都在一天结束时重复
def sched ():
i = 0
for (i <= 23):
x = datetime.today()
current_hour = datetime.now().hour
y=x.replace(day=x.day+1, hour=i, minute=00, second=00, microsecond=00)
delta_t=y-x
secs=delta_t.seconds+1
t=Timer(secs, hello_world)
t.start()
i = i + 1
def sched():
i=0
对于(i这是因为您将循环限制为i您知道模运算符(%)吗?i%24将在除以24后返回余数,因此i将为0,1,…23,0..等等
def sched ():
i = 0
while True:
x = datetime.today()
current_hour = datetime.now().hour
y=x.replace(day=x.day+1, hour=i, minute=00, second=00, microsecond=00)
delta_t=y-x
secs=delta_t.seconds+1
t=Timer(secs, hello_world)
t.start()
i = i + 1
i = i % 24
def sched ():
i = 0
while True:
x = datetime.today()
current_hour = datetime.now().hour
y=x.replace(day=x.day+1, hour=i, minute=00, second=00, microsecond=00)
delta_t=y-x
secs=delta_t.seconds+1
t=Timer(secs, hello_world)
t.start()
i = i + 1
i = i % 24