checking existance of a variable..

hi.

i would like to say in a python script:

if GameLogic.variable EXISTS:

someone suggested that it was

if GameLogic.variable:

but this doesn’t work.

This is because i want to say, if an object has a certain property then do such and such.

I won’t believe that this is not possible because it seems too useful and i could write a class myself to do it if i had to but there should be an easy way.

until this post i have been using try: except: to test existance. by doing an operation on it, it means that the variable exists if you don’t get an error.

however this is a crap way of doing it so…Help

-Luke

uhh, there are a few ways, I think they boil down to the same, I shall even provide a useful example

inGameBlender = 1
try:
     import GameLogic
catch:
     inGameBlender = 0

there also in python the builtin function
(copied from python docs)

hasattr(object, name)
The arguments are an object and a string. The result is 1 if the string is the name of one of the object’s attributes, 0 if not. (This is implemented by calling getattr(object, name) and seeing whether it raises an exception or not.)