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

Chr*_*urm 2 python macos datetime python-2.7

一些非常简单的代码会导致一个神秘的错误,Google没有给我任何帮助......

码:

import sys
import datetime

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

stdin上的前几个输入行:

20101119T141500
20101119T164500
20110310T081500
20110310T113000
20100218T113000
...
Run Code Online (Sandbox Code Playgroud)

错误:

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
Run Code Online (Sandbox Code Playgroud)

平台:Mac OS X 10.7.3,Python 2.7.1

Ign*_*ams 13

您调用了脚本"time.py",模糊了time模块.不要那样做.