How to check the exists of a name?
Ben Finney
ben+python at benfinney.id.au
Sun Oct 18 03:00:06 EDT 2009
David <71david at libero.it> writes:
> Il Sat, 17 Oct 2009 23:43:36 -0700 (PDT), StarWing ha scritto:
>
> > I got a idea, use a try...except statement. there are another way to
> > do it ?
> >
> > (I just curious now, because I solve my problem in another way :-)
>
> locals().has_key(myname)
> globals().has_key(myname)
The ‘dict.has_key’ method is deprecated, and is removed in Python 3.
The ‘in’ operator now works on dict objects:
'foo' in locals()
'foo' in globals()
--
\ “We must become the change we want to see.” —Mahatma Gandhi |
`\ |
_o__) |
Ben Finney
More information about the Python-list
mailing list