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