I have a list of functions. I would like to loop through the list and try if one of the functions goes well without error. I tried this:
list_functions = [func1(var), func2(var)]
for function in list_functions:
try:
function
except:
pass
else:
break
else:
raise Exception("No function succeeded.")
But my code tries only the func1
and then fails. How can I fix my code, please?
This question did not help me: Get a Try statement to loop around until correct value obtained