How to check the exists of a name?

Chris Rebert clp2 at rebertia.com
Sun Oct 18 02:54:37 EDT 2009


On Sat, Oct 17, 2009 at 11:43 PM, StarWing <weasley_wx at sina.com> wrote:
> On 10月18日, 下午2时37分, Chris Rebert <c... at rebertia.com> wrote:
>> On Sat, Oct 17, 2009 at 11:30 PM, StarWing <weasley... at sina.com> wrote:
>> > 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?
>>
>> You should avoid needing to do that in the first place. Common
>> alternatives include using a dict instead of variables, depending on
>> your circumstances.
>
> Okay... Thank you... But if I want to do that, what shall I do?
>
> 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 :-)

Perhaps if you could explain why there's the possibility these
variables might not be defined...

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list