有没有办法简化代码流,使busy = 0
和print busy
不必出现两次?
busy = 1
try:
print 1/0
busy = 0
print busy
except:
busy = 0
print busy
raise
最佳答案
您可以将其放入finally
子句中:
try:
print 1/0
except:
raise
finally:
busy = 0
print busy
但是正如@Ryan在评论中提到的,现在
except:
子句中有一些无用的代码。所以你可以做:try:
print 1/0
finally:
busy = 0
print busy