[Python-ideas] Retrying EAFP without DRY

Bruce Leban 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:
>        # try block
>    except:
>        # except block
>    retry:
>        # retry block
>    else:
>        # else block
>    finally:
>        # 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:

    # block
    # block
    if condition: retry

The equivalent of this in current Python is

while True:
        # block
        # block
        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'.

--- Bruce
Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120120/e067c101/attachment.html>

More information about the Python-ideas mailing list