如何抑制 Python AttributeError?
How to suppress a Python AttributeError?
当我 运行 ArcGIS Pro Add Geometry Attributes (Data Management) 命令时:
arcpy.AddGeometryAttributes_management()
我收到以下错误:
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'ToolValidator' object has no attribute 'isLicensed'
该工具执行其需要执行的操作并且工作正常。然而,做一点研究表明这是一个 known bug 并且应该被忽略:
Yes, given that there is no license requirement for the tool
(https://pro.arcgis.com/en/pro-app/tool-reference/conversion/table-to-excel.htm#L_)
just ignore and move on. I've pinged the gp team to make sure they
can take a look at this recently reported issue. I apologize you're
running into it, but looks like it isn't major...
有什么方法可以完全抑制这样的 AttributeError
,这样我就不会在更大的工作流程中看到错误了吗?
只需 运行 一个 try-except
块围绕要忽略错误的代码行。
try:
arcpy.AddGeometryAttributes_management()
except AttributeError:
pass
这将忽略错误并继续。
鉴于错误似乎在模块中,您可以只使用 except:
但是这将忽略返回的每个错误。
当我 运行 ArcGIS Pro Add Geometry Attributes (Data Management) 命令时:
arcpy.AddGeometryAttributes_management()
我收到以下错误:
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'ToolValidator' object has no attribute 'isLicensed'
该工具执行其需要执行的操作并且工作正常。然而,做一点研究表明这是一个 known bug 并且应该被忽略:
Yes, given that there is no license requirement for the tool (https://pro.arcgis.com/en/pro-app/tool-reference/conversion/table-to-excel.htm#L_) just ignore and move on. I've pinged the gp team to make sure they can take a look at this recently reported issue. I apologize you're running into it, but looks like it isn't major...
有什么方法可以完全抑制这样的 AttributeError
,这样我就不会在更大的工作流程中看到错误了吗?
只需 运行 一个 try-except
块围绕要忽略错误的代码行。
try:
arcpy.AddGeometryAttributes_management()
except AttributeError:
pass
这将忽略错误并继续。
鉴于错误似乎在模块中,您可以只使用 except:
但是这将忽略返回的每个错误。