[Python-ideas] except expression

Jan Kaliszewski zuo at chopin.edu.pl
Thu Feb 20 22:10:03 CET 2014


20.02.2014 02:18, Chris Angelico wrote:

> Time to open up this branch of the discussion... colon or arrow?
>
> For the purposes of this debate, I'm comparing these two notations,
> and nothing else:
>
> result = 1/x except ZeroDivisionError -> NaN

+ 0.1 from me.

> result = 1/x except ZeroDivisionError: NaN

+ 0.2 from me.

But I see a problem with the latter when it is used at
the beginning of a block statement, such as if or while
-- consider the following example:

     while 1 % x except ZeroDivisionError: 0:        ...

These two colons, very close to each other, look weird.
IMHO within parens it looks better a bit but still is not ideal:

     while (1 % x except ZeroDivisionError: 0):
         ...

And with arrow?

     while 1 % x except ZeroDivisionError -> 0:
         ...

I believe the arrow + parens variant is nicer a bit:

     while (1 % x except ZeroDivisionError -> 0):
         ...

Also, I still like the "short-paren" variant (as the
parens are closer to each other which allow my eyes to
match the parens easier):

     while 1 % x except (ZeroDivisionError: 0):
         ...

...or maybe:

     while 1 % x except (ZeroDivisionError -> 0):
         ...

So finally... Hm... Dunno. :)

Cheers.
*j



More information about the Python-ideas mailing list