Multiple exception syntax

Gabriel Genellina gagenellina at softlab.com.ar
Sat Jan 3 02:25:55 CET 2004


At 2/1/2004 09:58, you wrote:

>Normally in Python there is no need to write parenthesis for a tuple :
>a,b,c=(1,2,3)
>(a,b,c)=1,2,3
>
>are the same, and so are :
>
>for (x,y) in enumerate(aList)
>for x,y in enumerate(aList)
>
>But with "except" the behaviour is very different with or without
>parenthesis :
>- "except x,y" means : if exception x is raised, then y is the instance of
>the x class holding information about the exception
>- "except (x,y)" means : if one of the exceptions x or y is raised (or both)
>
>So it took me some time to figure out why this code was wrong :

I've been hit by the same error a couple of times.


>I find this confusing. It would be clearer for me to have :
>
>"except Error1 or Error2 or Error3"

I agree.


Gabriel Genellina
Softlab SRL





More information about the Python-list mailing list