I\'d just like to exit out of a with statement under certain conditions:
with
with open(path) as f: print \'before condition\' if
The best way would be to encapsulate it in a function and use return:
return
def do_it(): with open(path) as f: print 'before condition' if : return print 'after condition'