How to check the exists of a name?

David 71david at libero.it
Sun Oct 18 02:43:26 EDT 2009


Il Sat, 17 Oct 2009 23:30:02 -0700 (PDT), StarWing ha scritto:

> Sometimes I want to make a simple flags. and i need to check there is
> a name in current scope or not (that is, we can visit this name, no
> matter where is it). and how to do that in python?

Just use it in a try..except block.

try:
    print myname
except NameError:
    print "myname does not exists"


D.



More information about the Python-list mailing list