Danny Yoo wrote:

> I should have added that you can write your own context manager for
> requests; it shouldn't be too bad.  I'd expect the helper code to be
> something like:

> class AutoClosable(object):
>     def __init__(self, closable):
>         self.closable = closable
> 
>     def __enter__(self):
>         return self.closable
> 
>     def __exit__(self, type, value, traceback):
>         self.closable.close()
>         ## reraise exception if one occurred:
>         return False

There is also

<https://docs.python.org/dev/library/contextlib.html#contextlib.closing>


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to