contextlib.contextmanager and try/finally

Neil Cerutti neilc at norwich.edu
Wed Jan 11 11:46:17 EST 2012


On 2012-01-11, johannh at gmail.com <johannh at gmail.com> wrote:
> That suggests that I cannot rely on the
> contextlib.contextmanager decorator to ensure that the
> connection is closed and would have to write my own object with
> __enter__ and __exit__ methods to guarantee this.

contextmanager wraps your generator in an object with __enter__
and __exit__ methods for you.

-- 
Neil Cerutti



More information about the Python-list mailing list