existence of a variable

Skip Montanaro skip at mojam.com
Fri Jan 28 18:05:20 EST 2000


    Martin> What is the best way to determine existence of a variable in
    Martin> Python (I need to check if a variable is defined and if so,
    Martin> delete it)?

One option is

    try:
        del v
    except NameError:
        pass

Skip Montanaro | http://www.mojam.com/
skip at mojam.com | http://www.musi-cal.com/
847-971-7098
"Languages that change by catering to the tastes of non-users tend
not to do so well." - Doug Landauer




More information about the Python-list mailing list