本文介绍了怎么把Python 2的'from Queue import Queue,Empty'转换成Python 3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将用Python 2编写的源代码转换为Python 3,我偶然发现了这一点:
I'm converting a source code written in Python 2 to Python 3 and I stumbled into this:
from Queue import Queue, Empty
我将其更改为:
from multiprocessing import Queue, Empty
但这给了我一个例外:
ImportError: cannot import name 'Empty'
我该如何解决?
推荐答案
multiprocessing.Queue
用于过程,不要让大小写混淆您. Queue
,它已重命名为 queue
用于线程.
multiprocessing.Queue
is used for processes, don't let the capitalization confuse you. Queue
, which was renamed to queue
in Python 3, is for threads.
Empty
和 Queue
位于queue
模块中,因此请从那里获取它们.
Both Empty
and Queue
are located in the queue
module, so grab them from there.
这篇关于怎么把Python 2的'from Queue import Queue,Empty'转换成Python 3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!