Test if variable exists in python
Here is how to test if a variable exists
try: x
except NameError:
# x doesn't exist, do something
else:
# x exists, do something else
try: x
except NameError:
# x doesn't exist, do something
else:
# x exists, do something else
Comments