find isset() php function equivalent in python

Max M maxm at mxm.dk
Tue Feb 1 04:39:31 EST 2005


Ola Natvig wrote:
> 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



More information about the Python-list mailing list