【发布时间】:2021-01-19 16:29:29
【问题描述】:
我正在枚举列表中的一些对象,这些对象可能具有也可能不具有某些属性。如果属性不存在,我会得到AttributeError。我想要做的是捕获异常对象并检索导致错误的特定属性并将其设置为空字符串。我在AttributeError 对象中没有看到任何方法来检索所述属性。
这里有部分代码:
import wmi
c = wmi.WMI ()
for account in c.Win32_Account():
try:
print(f"Name: {account.Name}, FullName: {account.FullName}, LocalAccount: {account.LocalAccount}, Domain: {account.Domain}")
except AttributeError as error:
# How do I retreive the attribute in question from the exception object?
【问题讨论】:
标签: python python-3.x exception