<div dir="ltr">I'm happy you're for it. Maybe one day we'll see a Python 4 with no second argument to dict.get, getattr and so many others...</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Feb 13, 2014 at 2:08 AM, Raymond Hettinger <span dir="ltr"><<a href="mailto:raymond.hettinger@gmail.com" target="_blank">raymond.hettinger@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div class="h5"><br><div><div>On Feb 12, 2014, at 9:02 PM, Ram Rachum <<a href="mailto:ram.rachum@gmail.com" target="_blank">ram.rachum@gmail.com</a>> wrote:</div>
<br><blockquote type="cite"><div style="font-family:ArialMT;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
Here's an idea that would help shortening code. Allow a ternary expression based on except, like so:</div><div style="font-family:ArialMT;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<br></div><div style="font-family:ArialMT;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
first_entry = entries[0] except IndexError else None</div><div style="font-family:ArialMT;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
item = my_queue.get() except queue.Empty else None</div><div style="font-family:ArialMT;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
response_text = request('<a href="http://whatever.com'" target="_blank">http://whatever.com'</a>).text except HttpError else "Can't access data"</div><div style="font-family:ArialMT;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<br></div><div style="font-family:ArialMT;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
Aside from the fact that this would be a big grammar addition, a big problem here is the usage of the `else` keyword, that when used with except usually means "what would happen if there wasn't an exception" and here means the opposite. But I couldn't think of a nicer syntax.</div>
<div style="font-family:ArialMT;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<br></div><div style="font-family:ArialMT;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
I realize that this is a big change and that most people would be opposed to this... But I guess I just wanted to share my idea :)</div></blockquote></div><br></div></div><div>I would like to see something like this come to fruition.</div>
<div>We need a clean way to express the idea of "take an</div><div>arbitrary, exception-raising function and give it a default</div><div>argument".</div><div><br></div><div>Hopefully, this would end the gradual but never-ending requests</div>
<div>to bloat APIs with "default" arguments. For example, if your idea</div><div>or some variant had been in place, the min() and max() functions</div><div>likely wouldn't have grown complex signatures in Python 3.4.</div>
<span class="HOEnZb"><font color="#888888"><div><br></div><div><br></div><div>Raymond</div><div><br></div></font></span></div></blockquote></div><br></div>