Newbie: is a variable defined?
John Hunter
jdhunter at ace.bsd.uchicago.edu
Fri Dec 20 15:26:49 EST 2002
More information about the Python-list mailing list
Fri Dec 20 15:26:49 EST 2002
- Previous message (by thread): Newbie: is a variable defined?
- Next message (by thread): Newbie: is a variable defined?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>>>>> "Christopher" == Christopher Swingley <cswingle at iarc.uaf.edu> writes: Christopher> Greetings, Short version: I'm wondering how you test Christopher> variables to see if they've been defined or not. A standard idiom for this is try: efrom except AttributeError: select_default(with_default) else: select_using(efrom) It sometimes is useful in variants of this approach to be able to delete efrom after using it, in which case you can use 'del efrom' Many prefer the above to the look before you leap approach: efrom = None efrom = try_to_get_efrom() if efrom is not None: do_something(efrom) else: do_something_else() John Hunter
- Previous message (by thread): Newbie: is a variable defined?
- Next message (by thread): Newbie: is a variable defined?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list