一些非常简单的代码会导致一个神秘的错误,谷歌什么都没给我......
代码:
import sys
import datetime
for line in sys.stdin:
date = datetime.datetime.strptime(line, '%Y%m%dT%H%M%S')
print date
stdin上的前几行输入:
20101119T141500
20101119T164500
20110310T081500
20110310T113000
20100218T113000
...
错误:
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
平台:Mac OS X 10.7.3,Python 2.7.1
答案 0 :(得分:13)
您调用了脚本“time.py”,隐藏了time
模块。不要那样做。