Feature Request: Reposition Execution

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed May 13 05:07:37 EDT 2015


On Wednesday 13 May 2015 17:27, Christian Gollwitzer wrote:

> A clean way to exit your script could be to raise an exception. It
> should propagate to the toplevel and halt your script. However it is not
> possible to back and resume the execution.

while True:
    try:
        run_script()  # May raise TryAgain
        break
    except TryAgain:
        pass


If you prefer to only retry a finite number of times:


for i in range(10):
    try:
        run_script()  # May raise TryAgain
        break
    except TryAgain:
        pass
else:
    # break skips past the for...else block
    raise GiveUpError('too many failures')





-- 
Steve




More information about the Python-list mailing list