[Python-ideas] except expression
Ram Rachum
ram.rachum at gmail.com
Thu Feb 13 01:14:45 CET 2014
More information about the Python-ideas mailing list
Thu Feb 13 01:14:45 CET 2014
- Previous message: [Python-ideas] except expression
- Next message: [Python-ideas] except expression
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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... On Thu, Feb 13, 2014 at 2:08 AM, Raymond Hettinger < raymond.hettinger at gmail.com> wrote: > > On Feb 12, 2014, at 9:02 PM, Ram Rachum <ram.rachum at gmail.com> wrote: > > Here's an idea that would help shortening code. Allow a ternary expression > based on except, like so: > > first_entry = entries[0] except IndexError else None > item = my_queue.get() except queue.Empty else None > response_text = request('http://whatever.com').text except HttpError > else "Can't access data" > > 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. > > 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 :) > > > I would like to see something like this come to fruition. > We need a clean way to express the idea of "take an > arbitrary, exception-raising function and give it a default > argument". > > Hopefully, this would end the gradual but never-ending requests > to bloat APIs with "default" arguments. For example, if your idea > or some variant had been in place, the min() and max() functions > likely wouldn't have grown complex signatures in Python 3.4. > > > Raymond > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140213/2e78a67e/attachment.html>
- Previous message: [Python-ideas] except expression
- Next message: [Python-ideas] except expression
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list