AttributeError: module 'threading' has no attribute 'Thread'

mac2022-06-30  31

/usr/local/bin/python2.7 "/Volumes/NO NAME/work/djangorestful_hui-master/tutorial/threading.py" Traceback (most recent call last):   File "/Volumes/NO NAME/work/djangorestful_test-master/tutorial/threading.py", line 3, in <module>     import threading   File "/Volumes/NO NAME/work/djangorestful_test-master/tutorial/threading.py", line 14, in <module>     t1 = threading.Thread(target=music, args=('爱的故事', 3)) AttributeError: 'module' object has no attribute 'Thread'

Process finished with exit code 1

名字叫threading.py,在程序中使用了threading.Thread,报错。

原因是自己编写的文件和系统中的文件名重名,优先使用了自己写的threading文件。

更换文件名为:threadingDemo.py。

运行成功,建议在取名时,大家尽量不要使用系统关键字。

最新回复(0)