@contextlib.contextmanager def manager(*args): object = initialize(args) try: yield object finally: # cleanup object.close()