0
我需要使用python hasattr
来实现我的特定目的。我需要检查一个对象是否有属性,并且不是有另一个属性。在python中使用hasattr而不是hasattr
考虑类对象命名model
,我需要检查它是否具有属性称为domain_id
:
if hasattr(model, 'domain_id'):
我还需要检查的一个条件,它不应该有属性,叫做type
。
if not hasattr(model, 'type'):
如何在这里结合两个检查?
你的问题标题已经有你的答案了。 –
如果hasattr(model,'domain_id')不是hasattr(model,'type'):'work? –