Test the existence of a variable?

Robin Becker robin at reportlab.com
Fri Sep 3 06:41:28 EDT 2004


Thierry S. wrote:

> Hello.
> 
> I would to test the existence of a variable before to use it (like
> isset($myVar) in PHP).
> I try using "if myVar: ", but there is the error meesage (naturally):
> "NameError: name 'myVar' is not defined"
> 
> Please, could you tell me what for function exist to test the variable with
> Python?
> 
> Regards,
if globals().has_key('myVar'):
     ....

-- 
Robin Becker



More information about the Python-list mailing list