class Point: def __init__(self): print('init') def __enter__(self): print('enter'+self.__class__.__name__) return self def __exit__(self, exc_type, exc_val, exc_tb): print('exit'+self.__class__.__name__) print(exc_tb) print(exc_val) print(exc_type) p = Point() with p as f: # raise Exception('Error123') print(f == p) print(f is p )