2017-05-28 178 views

回答

0
import time 
import datetime 

def somefunction(x): 
    return x 


x = True 
while x: 
    a = datetime.datetime.now().hour 

    if a < 22: 
     time.sleep(1) 
     somefunction(x) 

    else: 
     x = False 

或:

script1.py

import datetime 

a = datetime.datetime.now().hour 

script2.py

from script1 import a 
import time 



def somefunction(x): 
    return x 



while a < 22: #execute function as long it is less than 22.00, else stop 

    time.sleep(1) 
    somefunction(x) 

或者,如果您有任何其他背景的來源,這將是一件好事知道這是什麼是。

+0

這是如何與其他代碼並行(在後臺)? – Matthias