are variables local only to try/except blocks?

Fredrik Lundh fredrik at pythonware.com
Mon Sep 19 17:05:09 CEST 2005


BarrySearle wrote:

> # Is this valid

yes.

> (or is excp local to try/except)?

no.  try/except doesn't introduce a new scope.

> try:
>    try:
>       doSomething1
>       excp = 0
>    except:
>       excp = 1
>    #endTry
>    if (_excp_): doSomething1 # is excp defined here?

yes (but _excp_ isn't defined, so you need to change that if-statement)

>    excp = 0
> except:
>    excp = 1
> #endTry
> if (excp): doSomething2 # is excp defined here?

yes.

</F> 






More information about the Python-list mailing list