Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Very simple strptime() call throws error

Some very simple code leads to a mystifying error, and Google gives me nothing...

Code:

import sys
import datetime

for line in sys.stdin:
    date = datetime.datetime.strptime(line, '%Y%m%dT%H%M%S')
    print date

First few input lines on stdin:

20101119T141500
20101119T164500
20110310T081500
20110310T113000
20100218T113000
...

Error:

Traceback (most recent call last):
  File "time.py", line 5, in <module>
    date = datetime.datetime.strptime(line, '%Y%m%dT%H%M%S')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_strptime.py", line 13, in <module>
    import time
  File "<path>", line 5, in <module>
    date = datetime.datetime.strptime(line, '%Y%m%dT%H%M%S')
AttributeError: _strptime

Platform: Mac OS X 10.7.3, Python 2.7.1

like image 258
Christoph Wurm Avatar asked Dec 21 '25 04:12

Christoph Wurm


1 Answers

You called your script "time.py", shadowing the time module. Don't do that.

like image 152
Ignacio Vazquez-Abrams Avatar answered Dec 22 '25 18:12

Ignacio Vazquez-Abrams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!