24 Jul
2002
24 Jul
'02
1:54 p.m.
Ed Leafe wrote:
<alert type="newbie"> How do I test if a value exists in Python? I'd really like to avoid using try/except if possible. I need to do something like:
if defined(x): print 'x is cool' else: print 'x does not exist'
</alert>
i use the locals() builtin -- it returns a dictionary containing the current symbol table, you can use something like locals().has_key('var') this isnt allowed in pythonscripts though. why the aversion against try/except (just curious)? - peter.