[Python-Dev] Chaining try statements: eltry? (original) (raw)

Guido van Rossum gvanrossum at gmail.com
Thu Jul 7 20:54:49 CEST 2005


[Guido, on {for,while}/else] ... > The question remains whether Python would be easier to learn without > them. And if so, the question would remain whether that's offset by > their utility for experienced developers. All hard to assess > impartially!

[Tim saves the day]

That's what I'm here for. I like loop "else" clauses, but have to admit that (a) I rarely use them; (b) most of the time I use them, my control flow is on the way to becoming so convoluted that I'm going to rewrite the whole function soon anyway; and, (c) I've often misread code that uses them, mentally attaching the "else" to a nearby "if" instead.

I also suspect that if they weren't in the language already, a PEP to introduce them would fail, because stilllooking = True some loop: if found it: stilllooking = False break if stilllooking: # what would have been in the "else" clause is clear and easy to write without it.

OTOH I don't particularly like code that requires flag variables; they often make me squirm because the same condition (flag) is tested multiple times where it could be tested just once if more sophisticated flow control (e.g. an else clause :) was available.

How would a PEP to remove this feature fare today?

Unhelpfully,

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list