1

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*

2

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.