我收到此错误 'module' object has no attribute '_strptime'
但仅当我使用多个线程时。当我只使用一个时,它工作正常。我使用 python 2.7 x64。这里是我调用的简化函数
import datetime
def get_month(time):
return datetime.datetime.strptime(time, '%Y-%m-%dT%H:%M:%S+0000').strftime("%B").lower()
这是完整的回溯:
AttributeError: 'module' object has no attribute '_strptime'
Exception in thread Thread-22:
Traceback (most recent call last):
File "C:\Python27x64\lib\threading.py", line 810, in __bootstrap_inner
self.run()
File "C:\Python27x64\lib\threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "C:\file.py", line 81, in main
month=get_month(eventtime)
File "C:\file.py", line 62, in get_month
return datetime.datetime.strptime(time, '%Y-%m-%dT%H:%M:%S+0000').strftime("%B").lower()
AttributeError: 'module' object has no attribute '_strptime'
最佳答案
我可以确认该问题与多线程有关,当我将 datetime.datetime.strptime
与 ThreadPool
模块结合使用时,我偶尔会遇到这种情况。
我可以通过导入“缺失”模块在我的脚本中解决这个问题,如下所示:
import _strptime
关于python - “模块”对象没有属性 '_strptime',有多个线程 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32245560/