“模块"对象不具有带有多个线程的Python属性"_strptime" [英] 'module' object has no attribute '_strptime' with several threads Python

查看:106
本文介绍了“模块"对象不具有带有多个线程的Python属性"_strptime"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误'module' object has no attribute '_strptime',但仅当我使用多个线程时.当我只使用一个时,它工作正常.我正在使用python 2.7 x64.在这里,我们正在调用简化的函数

I'm getting this error 'module' object has no attribute '_strptime' but only when I use several threads. When I only use one it works fine. Im using python 2.7 x64. Here there us the reduced function i'm calling

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'

推荐答案

恰好遇到了这个确切的问题.这是一个棘手的问题-我花了一个小时左右的时间来进行追踪.我尝试启动外壳程序并输入以下代码:

Just ran into this exact problem. It's a tricky one - took me an hour or so to track it down. I tried launching the shell and entering in the following code:

import datetime

print(datetime.datetime.strptime("2015-4-4", "%Y-%m-%d"))

这很好.然后,我在工作区的空白文件中尝试了此操作.这给出了与您描述的相同的错误.我尝试从工作区中的命令行运行它.仍然给出了错误.然后,我从工作区启动了外壳程序.这次,它在shell环境中产生了错误.事实证明,除我所在的目录外,其他任何目录都可以正常工作.

This worked fine. Then I tried it in a blank file in my workspace. This gave the same error you described. I tried running it from the command line in my workspace. Still gave the error. I then launched the shell from my workspace. This time it gave the error in the shell environment. As it turned out, any directory other than the one I was in worked fine.

问题是我的项目是python日历应用程序,我的主文件名为"calendar.py".这与某些本机导入冲突,从而产生了奇怪的错误.

The problem was that my project was a python calendar app, and my main file was called "calendar.py". This conflicted with some native import, thus creating the bizarre error.

就您而言,我敢打赌任何问题都出在您文件的名称上:"file.py".给它起个别的名字吧,你应该很好.

In your case, I'd bet anything the problem is the name of your file: "file.py". Call it something else, and you should be good to go.

这篇关于“模块"对象不具有带有多个线程的Python属性"_strptime"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆