return in loop for ?
Peter Hansen
peter at engcorp.com
Thu Nov 24 07:53:00 EST 2005
Duncan Booth wrote:
> In practice it is impossible to write code in Python (or most
> languages) with only one return point from a function: any line could throw
> an exception which is effectively another return point, so the cleanup has
> to be done properly anyway.
def funcWithGuaranteedOneExitPoint():
try:
# do some stuff, or
pass
finally:
return None
Of course, you might have mistyped something (e.g. "none") and still
manage to get an exception, but at least in the above example it's still
only a single exit point, even if not the one you thought it was. ;-)
-Peter
More information about the Python-list
mailing list