python - 如何抑制 Python AttributeError?

标签 python error-handling attributeerror arcpy

当我运行 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:但是,这将忽略返回的每个错误。

关于python - 如何抑制 Python AttributeError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64096121/

相关文章:

python - 分组相似的条目python

python - 尝试将 'pop' 方法与 Python 中的列表一起使用时出错

batch-file - 批处理脚本错误级别帮助

java - 为什么我们不应该在 Java 中捕获错误?

python - python中递归方法的AttributeError

python - 跳过无数据网页的条件

python - 从 RDS 检索数据给出 AttributeError : 'sqlalchemy.cimmutabledict.immutabledict' object has no attribute 'setdefault'

python - 服务器基础设施、文件上传项目

python websockets,如何设置连接超时

php - 在 PHP 中处理文件系统函数的错误和警告的正确方法是什么?