Option
Script
class Example(object):
def __init__(self, arg):
self.arg = arg
def __enter__(self):
x = tear_up(self.arg)
return x
def __exit__(self, exc_type, exc_value, traceback):
if exc_type is not None: # Re-Raise Original exception with same traceback
raise exc_type, exc_value, traceback
tear_down()
return True
# Example Usage
with Example(arg) as x:
x.do_something()