How can I tell if variable is defined

Sean DiZazzo half.italian at gmail.com
Tue Sep 22 20:32:32 CEST 2009


On Sep 22, 11:03 am, "Brown, Rodrick " <rodrick.br... at citi.com> wrote:
> How could I do the following check in Python
>
> In Perl I could do something like if ((defined($a)) { ... }
>
> I tried if var is not None:
> However this doesn't seem to work as described.
>
> Thanks.

try:
    var
except NameError:
    handle_it()

~Sean



More information about the Python-list mailing list