Does a function like isset() exist in Python?

Tim Leslie tim.leslie at gmail.com
Wed Jun 22 23:32:56 EDT 2005


On 6/23/05, Patrick Fitzsimmons <patfitz at gmail.com> 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.

There's no direct function to acheive this however you can find out
the answer by looking in locals() and globals() dictionaries. Before
doing this though you should consider why you want to do it. A lot of
this time when this kind of thing comes up the problem can better be
solved by rearranging the code such that you don't need to check
isset() in the first place.

Tim

> 
> Thanks for any help,
> Patrick
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list