Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想让函数在每小时的最高峰开始(python)_Python_Python 2.7 - Fatal编程技术网

我想让函数在每小时的最高峰开始(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