A downside to the try...finally idiom, is that it litters your code
with the cleanup code for resources you acquire. The RAII idiom from C++
handles this by putting the cleanup code in the destructors.

Unfortunately, while python may have deterministic resource cleanup from
reference counting like C++ (Iron Python and Jython may not), you can't
reliably write your own destructors in python.

To make this nicer, python has with blocks, which allow the code for
cleanup to be kept with the code for allocation.

To use a with block, you pass it an object that obeys the context
manager protocol. There are dedicated context manager objects, and
some other objects, such as open files, can be used as context managers.