我有一个代码,它给了我错误:
ImportError: cannot import name datetime
我的代码是:
from datetime import datetime as dt
import time
while True:
if dt.now().second in range(0, 30): #start, stop are integers (eg: 6, 9)
# call to your scheduled task goes here
print "Yes " + str(dt.now().year) +" : "+ str(dt.now().month) +" : "+ str(dt.now().day) + str(dt.now().hour) +" : "+ str(dt.now().minute) +" : "+ str(dt.now().second)
time.sleep(10) # Minimum interval between task executions
else:
print "No " + str(dt.now().hour) +" : "+ str(dt.now().minute) +" : "+ str(dt.now().second)
time.sleep(10) # The else clause is not necessary but would prevent the program to keep the CPU busy.