Olivier Noblanc ATOUSOFT wrote:
Hello
What is the equivalent function of php isset() in python
try:
if variable:
# isset
pass
except NameError:
# not set
pass
you could use:
>>> 'variable' in vars()
But be aware that it is bad bad practice to do it like that.
If you need variables that you don't know that name of, you should put them in a dictionary. They are made for that exact purpose.
>>> unkown_vars = {} >>> unkown_vars['variable'] = 42 >>> 'variable' in unkown_vars True
--
hilsen/regards Max M, Denmark
http://www.mxm.dk/ IT's Mad Science -- http://mail.python.org/mailman/listinfo/python-list