Python:非常简单的strptime()调用抛出错误

时间:2012-04-27 19:30:05

标签: python macos datetime python-2.7

一些非常简单的代码会导致一个神秘的错误,谷歌什么都没给我......

代码:

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

1 个答案:

答案 0 :(得分:13)

您调用了脚本“time.py”,隐藏了time模块。不要那样做。