(original) (raw)
On Fri, Jan 20, 2012 at 4:36 PM, Mike Meyer <mwm@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:
try:
� � # block
except:
� � # block
� � if condition: retry
The equivalent of this in current Python is
while True:
� � try:
� � � � # block
� � except:
� � � � # block
� � � � if condition: continue # retry
� � break
FWIW, if this turns out to be a good idea, an alternate spelling that would not require a new keyword is 'try again'.
--- Bruce