Python 无法导入日期时间包

Python 无法导入日期时间包,python,python-2.7,python-datetime,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 p

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

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.

什么是导入日期时间;打印日期时间。_文件_告诉您是否已导入?您几乎肯定有另一个同名模块屏蔽了标准库。您的模块名是什么?如果您查看错误回溯,它几乎肯定会指向您自己创建的
datetime.py
。请将完整的错误回溯粘贴到您问题中的新代码块中。另外,代码的缩进不正确。我的问题解决了。错误是模块名和程序名相同。