# How do I look for objects with a particular property with a particular value using Python in the BGE?

I have a number of objects with the boolean property, and I need to write a script which specifies any object which has this property and whose value is set to True. I don't know how to phrase a definition for such an object though.

import bge

def findObjectByPropertyValue(propertyName, propertyValue):
return [object for object in bge.logic.getCurrentScene()
if propertyName in object and object[property] == propertyValue]


Alternative (This does not allow to search for value None as it can't distinguish between value None and not-present):

import bge

def findObjectByPropertyValue(propertyName, propertyValue):
return [object for object in bge.logic.getCurrentScene()
if propertyName.get(property) == propertyValue]