See If Vairiable Has A Value

how do you see if a variable has been initiated


if P_Run:
    print "P_Run has been set"
else:
    print "No Variable Named P_Run"

do you get what i mean?
Thank You

why? are you trying to do your own property testing near sensor in python? do you not like using try/except ValueError?

for example

if hasattr(gameobject,"propertyname"): print "has propertyname"

of course, the implementation is the same as a try statement… performance wise this might hurt but I haven’t played with that

try is always going to be faster, because you’re only putting Python through the “look-up attribute” code-path one time; not twice.

The possible alternate code-path of determining that an exception has occurred, raising it and diverting control to the appropriate handler is very fast because there is no searching involved.

Python code should be wrapped in try statements in any case, if only to provide meaningful context-information for messages when (not if…) bgus :wink: occur. It is much easier to find a problem when the message tells you not only what happened, but more-or-less “why, and where to look.” The additional overhead required to do this is essentially non-existent. All code should respond gracefully, and descriptively, to errors.

all python variable refrences are a hash table [dictionary] lookups

hasattr is syntatic sugar, I guess you make the case the difference is there in performance