Python:在每隔几分钟运行一次的程序中启动一次变量

时间:2016-10-24 07:53:59

标签: python initialization

我每分钟都有一个程序在运行。当我第一次执行它并执行其他操作时,我希望这样;像这样:

def alarm_function (alarm):
    first_time=0
    if first_time==0:
        send_on_website(message)
        first_time+=1
        alarm=0
    else:
        send_on_website(a_different_message)
    if alarm==0:
        #do nothing
    if alarm==1:
        alarm+=1
        #do something

所以基本上我执行一次后我想要删除第一行" first_time = 0"因为我不想再发起它。另外,我想在报警变量上创建一个计数器,它在程序中的某个位置启动。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

如果你不想再使用first_time,你必须定义一个新函数。对于计数器,您可以放在程序的顶部import time,无论您希望计数器在哪里使用time.sleep(?) #change ? for a any number of seconds