尝试直到有效

Ric*_*ard 0 python exception

有没有办法在Python中执行以下操作?

try:
  Thing1()
try_this_too:
  Thing2()
try_this_too:
  Thing3()
except:
  print "Nothing worked :-("
Run Code Online (Sandbox Code Playgroud)

请注意,如果Thing1()成功,我不想做任何其他事情.

mgi*_*son 8

for thing in (Thing1,Thing2,Thing3):
    try:
       thing()
       break  #break out of loop, don't execute else clause
    except:   #BARE EXCEPT IS USUALLY A BAD IDEA!
       pass
else:
    print "nothing worked"
Run Code Online (Sandbox Code Playgroud)