I was wondering if there is a good way to tell the python interpreter to go to the next / last function return statement .
Let's assume the following dummy code:
def foo(bar):
do(stuff)
if condition:
do(stuff)
if condition2:
do(stuff)
if condition3:
...
return (...)
Sometimes it gets very dirty with many conditions that I cannot use because they rely on the block do(stuff)above. Now I can do this:
def foo(bar):
do(stuff)
if not condition: return (...)
do(stuff)
if not condition2: return (...)
do(stuff)
if not condition3: return (...)
...
return (...)
It looks a little less dirty, but I will have to repeat the returned statement again and again, which is a bit reminiscent of, and if its long tuple or similar it even looks worse. The ideal solution would be to say "if not a condition, skip the final return statement". Is it possible?
:, : - ,