Does a function like isset() exist in Python?
George Sakkis
gsakkis at rutgers.edu
Thu Jun 23 01:56:08 EDT 2005
"Patrick Fitzsimmons" wrote:
> Hi,
>
> I'm sure I should know this, but I can't find it in the manual.
>
> Is there a function in Python like the function in PHP isset()? It
> should take a variable name and return True or False depending on
> whether the variable is initialized.
>
> Thanks for any help,
> Patrick
There are no unitialized variables in python; if you try to access an
undefined name, a NameError exception is raised:
try:
print "foo is", foo
except NameError:
print "foo is undefined"
To undefine a defined name, use del:
>>> foo=None
>>> print foo
None
>>> del foo
>>> print foo
NameError: name 'foo' is not defined
George
More information about the Python-list
mailing list