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 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -