I\'d just like to exit out of a with statement under certain conditions:
with
with open(path) as f: print \'before condition\' if
There exists a function __exit__() for this purpose. Syntax is as follows:
__exit__()
with VAR = EXPR: try: BLOCK finally: VAR.__exit__()