On 27/07/2019 09:19, Serhiy Storchaka wrote:
26.07.19 23:57, Guido van Rossum пише:
These are interesting ideas. It looks like you intend the except
clause of the for loop to *only* cover the iter() and next() calls
that are implicit in the for loop. You're right that it's awkward to
catch exceptions there.
Right. If you want to catch an exception in the loop body you have to
wrap the loop body with "try ... except". If you want to catch an
exception in the loop body *and* the 'for' clause you have to wrap the
whole "for" statement with "try ... except". No new syntax is needed for
this. But if you want to catch an exception *only* in the 'for' clause
you can't (without getting rid of the "for" statement at all).
However, I worry that when people see this syntax, they will think
that the except clause is for handling exceptions in the loop body.
(That's certainly what I assumed when I read just your subject line. :-)
I think people can make a mistake only when they see it for the first
time. After you learn what this syntax means, you will not make this
mistake the second time. The same applies to any other syntactic
construction.
I'm afraid I agree with Guido. I don't imagine I will use this feature
very often, and I can see myself making that mistake every time.
--
Rhodri James *-* Kynesim Ltd
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/FVLH7BHOHNWX2TITVAISHUP2YXX4X7U4/
Code of Conduct: http://python.org/psf/codeofconduct/