Test to see if variable exists

John Hunter jdhunter at ace.bsd.uchicago.edu
Tue Aug 12 12:19:13 EDT 2003


>>>>> "lamar" == lamar air <lamar_air at hotmail.com> writes:

    lamar> I need an if statement to test if a variable exists in a
    lamar> pyton script eg. if var1 exists: do this else: do this --


try: x
except NameError:
  # x doesn't exist, do something
else:
  # x exists, do something else

  





More information about the Python-list mailing list