我需要在程序之后继续执行,除非变量为True,但变量为False时需要退出程序。
我认为还会有其他情况,但我不确定如何使用它。
例如:
var = True
try:
print 2/0
except:
exit(1)
... continue executing
var = False
try:
print 2/0
except:
exit(1)
... exit
感谢您的评论。
最佳答案
这应该可以解决问题,因为您可能应该使用抬高。
var = True
try:
print 2/0
except:
if not var:
# I recommend using raise, as it would show you the error
exit(1)
关于python - Python try/except取决于变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35210530/