python 执行时报错AttributeError: 'dict' object has no attribute 'has_key'


问题:

python 执行时报错

sortedResult = self.sortResult(result.result)
File "D:\Python39\lib\HTMLTestRunner.py", line 642, in sortResult
if not rmap.has_key(cls):
AttributeError: 'dict' object has no attribute 'has_key'
[Finished in 0.2s with exit code 1]

解决方案:

查阅资料发现,Python3以后删除了has_key()方法

打开HTMLTestRunner.py该文件第642行,将 if not rmap.has_key(cls):改为 if not cls in rmap: 保存

再次运行脚本时,成功。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM