variable update

2006-09-12 Thread km
Hi all Is there any handy untility for checking if a variable is populated at runtime ? regards, KM -- http://mail.python.org/mailman/listinfo/python-list

Re: variable update

2006-09-12 Thread Fredrik Lundh
km wrote: Is there any handy untility for checking if a variable is populated at runtime ? access it, and catch the NameError: try: variable except NameError: print not defined else: print defined leaving variables undefined is usually bad style, though;

Re: variable update

2006-09-12 Thread Steve Holden
Fredrik Lundh wrote: km wrote: Is there any handy untility for checking if a variable is populated at runtime ? access it, and catch the NameError: try: variable except NameError: In a function when accessing a not-yet-bound local variable you may also (as

Re: variable update

2006-09-12 Thread Bruno Desthuilliers
Fredrik Lundh wrote: (snip) variable = None ... lots of code that may assign to variable ... if variable is not None: print not defined Shouldn't that be: if variable is None: print not defined ?-) Note to the OP: if None is a valid value for the

Re: variable update

2006-09-12 Thread Fredrik Lundh
Steve Holden wrote: access it, and catch the NameError: try: variable except NameError: In a function when accessing a not-yet-bound local variable you may also (as Fredrik knows but didn't bother to say) see an UnboundLocalError exception,

Re: variable update

2006-09-12 Thread Steve Holden
Fredrik Lundh wrote: Steve Holden wrote: access it, and catch the NameError: try: variable except NameError: In a function when accessing a not-yet-bound local variable you may also (as Fredrik knows but didn't bother to say) see an UnboundLocalError exception,