by akubera · 7y ago · 0 comments
methods = [method1, method2, method3, method4]
for method in methods:
try:
method()
except Exception:
pass
else:
break
else:
raise NoMethodWorked()
You can even pair specific exceptions to each method: methods = [(method1, TypeError), (method2, KeyError)]
for m, e in methods:
try: m()
except e: ...
But the whole thing really sounds like you're trying to do too much with one function and you really should rethink the whole structure of your code.