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

Comments

Sergiu said…
Thanks...i've been searching for this for a while. Yuo should post more on python :)
apoorvKumar said…
hmmm ... nice .... good work

Popular posts from this blog

Vim vi how to reload a file your editing