在python中使用hasattr而不是hasattr

时间:2015-11-20 07:38:59

标签: python

我需要使用python import SpriteKit import AVFoundation func playEffectSound(filename: String){ runAction(SKAction.playSoundFileNamed("\(filename)", waitForCompletion: false)) }// use this function to play sound playEffectSound("Sound File Name With Extension") // Example :- playEffectSound("BS_SpiderWeb_CollectEgg_SFX.mp3") 来达到我的特定目的。我需要检查一个对象是否具有属性,而具有另一个属性。

考虑名为hasattr的类对象,我需要检查它是否具有名为model的属性:

domain_id

我还需要检查一个不应该具有if hasattr(model, 'domain_id'): 属性的条件。

type

如何在这里结合两张支票?

1 个答案:

答案 0 :(得分:1)

只需将这两个条件与and

结合起来
if hasattr(model, 'domain_id') and not hasattr(model, 'type'):

只有在两个条件均为真时才会执行if块。

相关问题