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
Post a Comment