undefined variable ?

Guido Gloor haslo.ch at gmail.com
Sat Oct 16 11:14:31 EDT 2004


Are exceptions cheap in Python then? Coming from Java, I know there's
all sorts of overhead involved in creating and throwing an exception
there...

On Sat, 16 Oct 2004 13:20:08 +0100, Michael Hoffman
<m.h.3.9.1.without.dots.at.cam.ac.uk at example.com> wrote:
> vertigo wrote:
> 
> > How can i check if variable named var1 exists ?
> 
> It's frequently a better approach to assume that it does and catch an
> exception if it doesn't.
> 
> try:
>      var1
> except NameError:
>      var1 = "neW"
> 
> But why do you want to do this?
> --
> Michael Hoffman
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
http://www.haslo.ch/



More information about the Python-list mailing list