[Python-Dev] Py3k: Except clause syntax
brett at python.org
Fri Mar 17 22:28:31 CET 2006
On 3/17/06, Georg Brandl <g.brandl at gmx.net> wrote:
> Brett Cannon wrote:
> > On 3/17/06, Georg Brandl <g.brandl at gmx.net> wrote:
> >> John J Lee wrote:
> >> >> In your formulation the comma binds more tightly than the as keyword.
> >> >> In import statements it's the other way around. That seems like it
> >> >> might be a source of confusion.
> >> >
> >> > Perhaps parentheses around the exception list should be mandatory for the
> >> > 2-or-more exceptions case?
> >> >
> >> > except NameError as e: --> fine
> >> > except (NameError) as e: --> fine
> >> > except (NameError,) as e: --> fine
> >> >
> >> > except NameError, OtherError as e: --> SyntaxError
> >> > except (NameError, OtherError) as e: --> fine
> >> I don't like that particularly, but I guess that for consistency's sake
> >> it would have to be done this way.
> > I don't like it period. What consistency problem is there? This is
> > Python 3 we are talking about, so if something makes good sense such
> > as not having parentheses, I say leave them off. There are multiple
> > places where parens could be required but are not, like multiple
> > assignment.
> I only think of consistency with the usage of "as" in the import statement.
> I know how it works, but I predict people will come and write
> except NameError as e, OtherError as f:
Really? I don't. 'while' statement doesn't work that way either. I
don't personally associate 'as' with any specific statement that uses
Plus the above is bad since those should be separate 'except' clauses
if people need to differentiate between what exceptions they caught.
Otherwise it should be ambiguous and assigned to a single variable
More information about the Python-Dev