I\'d just like to exit out of a with statement under certain conditions:
with
with open(path) as f: print \'before condition\' if
f = open("somefile","r") for line in f.readlines(): if somecondition: break; f.close()
I dont think you can break out of the with... you need to use a loop...
[edit] or just do the function method others mentioned