The with statement was designed to simplify some common uses of try/finally, which guarantees that some operation is performed after a block of code, even if the block is terminated by return, an exception, or a sys.exit() call. The code in the finally clause usually releases a critical resource or restores some previous state that was temporarily changed.