Testing for a Variable
Brian Quinlan
BrianQ at ActiveState.com
Thu May 3 20:59:10 EDT 2001
Steve wrote:
> Probably not a good idea, in case var holds something like
> "system('rm *')".
> Since you only need to be sure it can be referenced, simply
> use a reference,
> as in:
>
> try:
> var
> except NameError:
> print "You lose"
>
> > # Do something
> > except NameError:
> > # Do something else
> >
> no-need-to-evaluate-what-can-simply-be-referred-to-ly y'rs -- Steve
The question is, of course, can you simply refer to it? You can't pass
around undefined variables but you can pass strings. And if the variable is
defined by your own application, hopefully it won't have unsafe code it in.
More information about the Python-list
mailing list