How can I tell if variable is defined

Grant Edwards invalid at invalid.invalid
Tue Sep 22 20:58:14 CEST 2009


On 2009-09-22, Brown, Rodrick <rodrick.brown at citi.com> wrote:

> How could I do the following check in Python
>
> In Perl I could do something like if ((defined($a)) { ... }

try:
    yourNameHere
except NameError:
    print "undefined"
else:
    print "defined"

> I tried if var is not None:
> However this doesn't seem to work as described.

As described where?

-- 
Grant Edwards                   grante             Yow! I feel like a wet
                                  at               parking meter on Darvon!
                               visi.com            



More information about the Python-list mailing list