python - Try until something works -


is there way following in python?

try:   thing1() try_this_too:   thing2() try_this_too:   thing3() except:   print "nothing worked :-(" 

note if thing1() succeeds, don't want else.

for thing in (thing1,thing2,thing3):     try:        thing()        break  #break out of loop, don't execute else clause     except:   #bare except bad idea!        pass else:     print "nothing worked" 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

c++ - How to test/verify that zero-initialization takes place -

node.js - Webpack/TypeScript Raising Errors When node_modules is Excluded -