retry in exception

Fredrik Lundh fredrik at pythonware.com
Fri Sep 29 15:14:49 EDT 2006


MonkeeSage wrote:

> I don't think python has any equivalent (could be wrong).

a trivial combination of while and try/except/else does the trick:

n = 0

while 1:
     try:

	# do something
	print n
	n = n + 1
	# make sure it fails a couple of times
	if n < 10:
	    raise ValueError

     except ValueError:
	pass # retry
     else:
	break # done




More information about the Python-list mailing list