无法导入datetime包

时间:2015-02-23 10:51:56

标签: python python-2.7 python-datetime

我有一个代码,它给了我错误:

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.

0 个答案:

没有答案