Reputation: 7313
I am trying to convert string date to timestamp in Python as described in the post here. When I run the code examples in the post, I encounter an error. For e.g.:
>>> import time
>>> import datetime
>>> s = "01/12/2011"
>>> time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())
Traceback (most recent call last):
File "<pyshell#31>", line 1, in <module>
time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())
File "C:\Python34\lib\_strptime.py", line 15, in <module>
import calendar
File "C:\Python34\calendar.py", line 9, in <module>
calendar = wckCalendar.Calendar(root, command=echo)
NameError: name 'wckCalendar' is not defined
>>>
It looks like at runtime the code implicitly tries to import calendar
and throws the error in the process. When I import calendar directly, I get the same error:
>>> import calendar
Traceback (most recent call last):
File "<pyshell#36>", line 1, in <module>
import calendar
File "C:\Python34\calendar.py", line 9, in <module>
calendar = wckCalendar.Calendar(root, command=echo)
NameError: name 'wckCalendar' is not defined
>>>
I just want to be able to do the following:
>>> import time
>>> import datetime
>>> s = "01/12/2011"
>>> time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())
Any ideas?
Python 3.4.1 on Windows 7 32 bit*
Upvotes: 1
Views: 1035
Reputation: 7313
Thanks to @J.F. Sebastian. I was caught in the name shadowing trap
. I made the stupid mistake of naming one of my modules calendar.py
. Once I removed this file, everything ran fine. I hope this post is not a waste and that someone may someday find it useful.
Upvotes: 1