A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2014-February/132819.html below:

[Python-Dev] PEP 463: Exception-catching expressions

[Python-Dev] PEP 463: Exception-catching expressionsChris Angelico rosuav at gmail.com
Thu Feb 27 12:07:08 CET 2014
On Thu, Feb 27, 2014 at 9:44 PM, Ronald Oussoren <ronaldoussoren at mac.com> wrote:
>> expr except Exception try default # "try" indicates the initial expr,
>> not the default
>
> I didn’t parse the expression this way at all, but quite naturally parsed is as “use expr, and try using default if expr raises Exception” and not as a RTL expression.

Thing is, in the statement form, "try doing this" means "do this, and
you might get an exception, so deal with it". In the 'try default'
form, "try this" means "oops, you got an exception, so try this
instead". It's using "try" in the opposite way.

>> default except Exception try expr # breaks L->R evaluation order
>>
>> Left to right evaluation order is extremely important to me.
>
> I agree with that, RTL evaluation would be pretty odd in Python.
>
> Really? The evaluation order you mention in above didn’t make sense to me until I tried to make sense of it.

The "default except Exception try expr" notation has "try" followed by
the thing that might raise an exception, which mimics the statement.
The "expr except Exception try default" notation evaluates from left
to right. Both make some sense, and I'd say it's on balance which is
the more likely to be expected. Imagine an overall expression where
it's ambiguous:

value = (d["foo"] except KeyError try d["spam"])

Which one do you expect to be tried first? I'd say you could poll a
bunch of moderately-experienced Python programmers and get both
answers in reasonable numbers.

ChrisA
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4