<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 28, 2014 at 1:30 AM, Glenn Linderman <span dir="ltr"><<a href="mailto:v+python@g.nevcal.com" target="_blank">v+python@g.nevcal.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#330033"><div><div class="h5">
    <div><br></div></div></div>
    <pre>    value = expr except (
        Exception1: default1,
        Exception2: default2,
        Exception3: default3,
   )

except that to get the pairing aspect of some parameters for a function call, you use = instead of :, and instead of a named function it has an expression and a keyword.</pre></div></blockquote><div>[ Cue people suggesting the use of '=' or '=>' or '->' instead of ':' ]</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF" text="#330033"><pre><span style="font-family:arial">Not being an expert parser generator, I don't know if the () could
    be made optional if there is only one exception-list, but that would
    also remove one of the benefits some folks might perceive with using
    this syntax, and would also make the analogy with function call
    syntax a little less comparable.</span></pre></div></blockquote><div>I believe it's possible, but it's probably tricky: the parser has to consider two or three cases:</div><div><br></div><div>1.  expr1 except expr2: expr4</div>
<div>2.  expr1 except (expr2: expr4)</div><div>3.  expr1 except (expr2, expr3): expr4</div><div>4.  expr1 except ((expr2, expr3): expr4)</div><div><br></div><div>(for simplicity I use 'expr' here, which is entirely the wrong thing to do in terms of CPython's grammar: there's different types of expressions for different situations. #2 and #4 are actually automatically derived from #1 and #3 by 'expr' including tuples and parenthesized expressions.) CPython's parser is a LL(1) parser, which means it can look ahead 1 character to choose between alternatives (and that's not going to change, Guido likes it this way -- and so I do, personally :). Looking at #2 and #3 you can't tell which alternative to use until you see the ':' or ',' after 'expr2', which is too late. The only way to handle that, I think, is to include all possible alternatives in the grammar for the 'except' statement, duplicating logic and definitions from a lot of places. We already do this kind of thing to deal with other potentially-ambiguous situations (to handle dicts and sets and dict comprehensions and set comprehensions, for example) but this would be even more duplication.</div>
<div><br></div><div>It would be easier if we weren't talking about '(' or any other token that can be part of a normal expression ;-P</div><div><br></div><div>[ Cue people suggesting the use of 'expr1 except < expr2: expr4 >'... ]</div>
<div><br></div></div>-- <br>Thomas Wouters <<a href="mailto:thomas@python.org" target="_blank">thomas@python.org</a>><br><br>Hi! I'm an email virus! Think twice before sending your email to help me spread!
</div></div>