[Python-ideas] Retrying EAFP without DRY
Ron Adam
ron3200 at gmail.com
Sat Jan 21 03:24:30 CET 2012
On Fri, 2012-01-20 at 16:36 -0800, Mike Meyer wrote:
> 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
>
> Would provide the same behavior as this code:
>
> while True:
> try:
> # try block
> except:
> # except block
> retry:
> # retry block
> else:
> # else block
> finally:
> # finally block
> break
This looks like it would be very tricky to get right from a python
programming stand point. Remember that python is full of one time
iterators that won't repeat properly on a second try. Also many function
calls mutate the arguments. So it's possible that a data structure
could be changed on the first try, and give different results on a
second try in an unexpected way.
Cheers,
Ron
More information about the Python-ideas
mailing list