Python Forum

Full Version: importing datetime trouble
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm new here, so please excuse if this is posted in the wrong place. I've been trying to learn Python, using ver. 3.6.4, and for the most part am enthused about it. But I haven't been able to import datetime. What gives? When I first downloaded Py, it worked for me, but not in the last week or so.
what happens when you import datetime? Do you get an error?
Yes, >>> import datetime
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import datetime
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\datetime.py", line 1, in <module>
import calendar
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\calendar.py", line 50, in <module>
class _localized_month:
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\calendar.py", line 52, in _localized_month
_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\calendar.py", line 52, in <listcomp>
_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
AttributeError: module 'datetime' has no attribute 'date'
>>>
Are you calling your own script datetime.py? If so, rename it to something that can't be imported in vanilla Python.
I though of playing with datetime and ended up creating file named: datetime.py

After couple of hours, I came across this post and realized what was wrong. Renamed my script file to datetime_xx and my issue was resolved.