In article <[EMAIL PROTECTED]>, Patrick Fitzsimmons <[EMAIL PROTECTED]> 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 The straight-forward thing would be to simply access the variable and catch any resulting NameError exception that's raised if it's not defined: try: x print "x is defined" except NameError: print "no it's not" Next question, why do you want to do this? I suspect for most idioms where you would something like this, the more pythonic way would be to set the variable to None at some point, then test to see if it's still None later on: x = None while foo: if blah: x = baz if x != None: print "x was assigned a value" -- http://mail.python.org/mailman/listinfo/python-list