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

本文介绍了一次因Python脚本中文件命名不当导致的错误,具体表现为与系统内置的threading模块名称冲突,通过更改自定义文件名解决了该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/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。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值