[Zope] Simple Python question

peter sabaini sabaini@inode.at
Wed, 24 Jul 2002 15:54:32 +0200


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.