Newbie: is a variable defined?

Andrew Lusk alusk at uiuc.edu
Fri Dec 20 16:23:34 EST 2002


Dennis Lee Bieber <wlfraed at ix.netcom.com> writes:

> Christopher Swingley fed this fish to the penguins on Friday 20 
> December 2002 11:26 am:
>
>> Greetings,
>> 
>> Short version: I'm wondering how you test variables to see if they've
>> been defined or not.
>>
>         You don't unless you use try/except blocks <G> 
>

Can't you do 

if "foo_var" in globals.keys():
   # etc etc 

?

--Andrew



More information about the Python-list mailing list