PyMOTW: contextlib

The contextlib module contains utilities for working with context managers and the with statement. Context managers are tied to the with statement. Since with is officially part of Python 2.6, you have to import it from __future__ before using contextlib in Python 2.5.

Read more at pymotw.com: contextlib