variables exist

Gerald Klix Gerald.Klix at klix.ch
Mon Apr 11 10:43:50 EDT 2005


try:
  myVariable
except NameError:
  print "Not bound"
else:
  print "Bound"

If you want to distinguish between the local an the global environment:

if globals().has_key( "myVariable" ):
  ...

versus

if locals().has_key( ".....


HTH,
Gerald

fabian schrieb:
> how testing if a variable exists in python as isset in php??
> 
> thanks

-- 
GPG-Key: http://keyserver.veridis.com:11371/search?q=0xA140D634




More information about the Python-list mailing list