[IronPython] How do I test if a variable is defined?

Michael Foord fuzzyman at voidspace.org.uk
Tue Nov 4 21:06:19 CET 2008


Marty Nelson wrote:
>
> How do I test in Iron Python (in python) if a variable is defined?
>
'name' in locals() or 'name' in globals()


try:
    name
except NameError:
    # variable 'name' is not defined

The second idiom is actually fairly common.

All the best,

Michael

> =======
> Notice: This e-mail message, together with any attachments, contains
> information of Symyx Technologies, Inc. or any of its affiliates or
> subsidiaries that may be confidential, proprietary, copyrighted,
> privileged and/or protected work product, and is meant solely for
> the intended recipient. If you are not the intended recipient, and
> have received this message in error, please contact the sender
> immediately, permanently delete the original and any copies of this
> email and any attachments thereto.
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog





More information about the Ironpython-users mailing list