打破还是退出“ with”陈述?
发布于 2021-01-29 18:30:45
我只想with
在某些情况下退出声明:
with open(path) as f:
print 'before condition'
if <condition>: break #syntax error!
print 'after condition'
当然,以上方法不起作用。有没有办法做到这一点?(我知道我可以反转条件:if not <condition>: print 'after
condition'
-像上面一样吗?)
关注者
0
被浏览
42
1 个回答