How to know when a variable is set

Justin Dubs jtdubs at eos.ncsu.edu
Wed Nov 14 16:43:38 CET 2001


"-" <madsurfer2000 at hotmail.com> wrote in message
news:fef0a228.0111140715.24b5cfc7 at posting.google.com...
> How can I test if a variable has been given a value, or if it's undefined?

I'm still playing with it.  Here's another way:

>>> foo = 5
>>> try: foo
... except NameError, detail: print detail
5
>>> try: bar
... except NameError, detail: print detail
name 'bar' is not defined
>>>

Have fun,

Justin Dubs





More information about the Python-list mailing list