python - 从 AttributeError 获取类和属性名称
问题描述
如何从 AttributeError 获取类和缺少的属性,例如,当 AttributeError 说:'NoneType' object has not attribute a
,我想获取"NoneType"
和"a"
。
解决方案
看起来您可以从 an 中检索的唯一内容AttributeError
是带有错误消息的字符串:
try:
str.s
except AttributeError as err:
error_message, = err.args
print("Error message:", error_message)
raise
推荐阅读
- compiler-errors - “lui a4,%hi(0x0001ff00)”的意外行为
- ios - 构建谓词(NSExpression)以确定 Mapbox SymbolStyle 图层的图标颜色
- javascript - 以块的形式反应js下载文件
- scheme - 如何将 ormap 应用于单个变量?- 方案
- sql - SQL Server 选择没有结果的变量
- windows - 如何获取工作目录中文件名超过30个字符的文件名写入文本文件?
- python - 在列表列表中查找单词
- gitlab - 如何将 Jira Atlassian 与 GitLab 云集成?
- angular - Angular 6 路径参数问题
- python - 使用 Matplotlib 绘制决策边界时出错