我正在尝试导入Queue,但一直收到以下错误提示:
Traceback (most recent call last):
File "threading.py", line 2, in <module>
import Queue
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/Queue.py", line 5, in <module>
import threading as _threading
File "/Users/zaq/threading.py", line 10, in <module>
queue = Queue.Queue()
AttributeError: 'module' object has no attribute 'Queue'
我正在使用链接中的代码Threading in python using queue
同时,我可以在Python解释器中导入和使用Queue。
我做错了什么?
Queue.Queue()
行,我本来期望它在第一次尝试使用线程模块时就失败了。 - Andrew ClarkQueue
尝试import threading
,而threading
又导入了你的模块。然后你的模块尝试import Queue
并使用Queue.Queue()
,但是Queue
仍处于正在导入的中间状态,所以它还没有Queue
成员。 - abarnert''
或'.'
)始终在sys.path
中的stdlib目录之前。导入你的模块并运行其顶层代码的原因是你将你的模块作为脚本运行,所以它被加载为__main__
而不是threading
。 - abarnert