with HTTPConnection as conn:

Hrvoje Niksic hniksic at xemacs.org
Thu Nov 18 16:55:00 CET 2010


Antoine Pitrou <solipsis at pitrou.net> writes:

> On Thu, 18 Nov 2010 12:46:07 +0100
> trylks <trylks at gmail.com> wrote:
>> Hi!
>> 
>> Would it be possible to use a with statement with an HTTPConnection object?
>> 
>> I know it is not possible at this moment, it doesn't implement an
>> __exit__ method, at least in version 3.1.1. I was wondering if the
>> __exit__ method should do something more than conn.close(), something
>> really hard or impossible, or if there are more requisites to use the
>> with statement beside of implementing that method. So far it seems
>> easy, useful and not done yet, so I'm probably mistaken about
>> something, and wondering what may that be.
>
> It's possibly one of those things that haven't been implemented simply
> because no one thought about it yet, or bothered enough to do it.

Also, contextlib.closing is readily available:

with contextlib.closing(HTTPConnection(...)) as conn:
    ...



More information about the Python-list mailing list