[Python-ideas] Retrying EAFP without DRY
bruce at leapyear.org
Sat Jan 21 02:40:15 CET 2012
On Fri, Jan 20, 2012 at 4:36 PM, Mike Meyer <mwm at mired.org> wrote:
> A single new keyword/clause, "retry". It has the same syntax as an
> "except" clause, can be used anywhere "except" can be used, and can be
> intermingled with them in the same try statement. There's probably a
> better syntax, but this is easy to describe.
> The behavior change from except is that instead of exiting the "try"
> statement when the "retry" clause ends, it restarts the try
> clause. In python, this code:
> # try block
> # except block
> # retry block
> # else block
> # finally block
Can you write this in terms of current Python code? I don't understand
exactly when a retry block would be executed. In Eiffel, retry is a
statement, not a clause. Analogous to that would be:
if condition: retry
The equivalent of this in current Python is
if condition: continue # retry
FWIW, if this turns out to be a good idea, an alternate spelling that would
not require a new keyword is 'try again'.
Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas