检查语句是否两次

时间:2019-03-19 14:28:39

标签: python-2.7 if-statement

我试图找到最好的方法来两次检查语句,而不必重写我的代码以尽可能使用循环。我有这段代码,

if something == True:
    #do stuff
else:
    if something_else():
        **#this is the condition I want to check again in 30-60 seconds and if it's still true then #do stuff**

    else:
        #do stuff

1 个答案:

答案 0 :(得分:0)

If you are only checking twice then just write a function and call it twice. you could use a sleep function for the wait.

import time

def check():
    if (1==1): #check goes here
        return 1
    else:
        return 0

if check(): #check 1
    print("check 1")
    time.sleep(5) #wait
    if check(): #check 2
        print("check 2")