with HTTPConnection as conn:

Chris Rebert clp2 at rebertia.com
Thu Nov 18 12:53:31 CET 2010

On Thu, Nov 18, 2010 at 3:46 AM, trylks <trylks at gmail.com> wrote:
> Hi!
> Would it be possible to use a with statement with an HTTPConnection object?

Yes, via http://docs.python.org/library/contextlib.html#contextlib.closing

from httplib import HTTPConnection
from contextlib import closing

with closing(HTTPConnection(...)) as conn:
    # do whatever
# connection now closed


More information about the Python-list mailing list