hasattr is not working

for a game i am making i am checing if an object has a specific property using hasattr i know it is set up correctly yet it appears as if hasattr is alway returning false, even if it should be true. is this new with 2.5+

import bge
Enemies = []
Dist = []
own = bge.logic.getCurrentController().owner
OL = bge.logic.getCurrentScene().objects
for object in OL:
    if hasattr(object, 'BG'):
        Enemies.append(object)
for object in Enemies:
    dist =own.getDistanceTo(object)
    Dist.append(dist)

it always ends up with empty lists even though there is an object with the property BG in the scene.
if i say if not hasattr … it comes up with every object even the one with BG.

For anyone who reads this:
Like I replied earlier, any version of Blender post 2.4 (and 2.49b) uses a dictionary to store object properties, not as attributes.
Therefore, you want to use:


if "BG" in object

and to set / get a property:


object['property'] = value
value = object['property']

1 Like