Re: nesting context managers

2011-12-20 Thread Ian Kelly
On Tue, Dec 20, 2011 at 11:46 AM, Ian Kelly wrote: > On Tue, Dec 20, 2011 at 9:56 AM, Ulrich Eckhardt > wrote: >> Am 20.12.2011 15:15, schrieb Ulrich Eckhardt: >> >>> Let us assume I had a class HTTPClient that has a socket for HTTP and a >>> logfile for filing logs. I want to make this HTTPClien

Re: nesting context managers

2011-12-20 Thread Ethan Furman
Rami Chowdhury wrote: On Tue, Dec 20, 2011 at 16:56, Ulrich Eckhardt wrote: To be extra safe or in more complicated scenarios, I could wrap this in a try-except and explicitly close those that were already created, but normally I'd expect the garbage collector to do that for me ... or am I then

Re: nesting context managers

2011-12-20 Thread Ian Kelly
On Tue, Dec 20, 2011 at 9:56 AM, Ulrich Eckhardt wrote: > Am 20.12.2011 15:15, schrieb Ulrich Eckhardt: > >> Let us assume I had a class HTTPClient that has a socket for HTTP and a >> logfile for filing logs. I want to make this HTTPClient a context >> manager, so that I can write >> >> with HTTPC

Re: nesting context managers

2011-12-20 Thread Rami Chowdhury
On Tue, Dec 20, 2011 at 16:56, Ulrich Eckhardt wrote: > To be extra safe or in more complicated scenarios, I could wrap this in a > try-except and explicitly close those that were already created, but > normally I'd expect the garbage collector to do that for me ... or am I then > implicitly assum

Re: nesting context managers

2011-12-20 Thread Ulrich Eckhardt
Am 20.12.2011 15:15, schrieb Ulrich Eckhardt: Let us assume I had a class HTTPClient that has a socket for HTTP and a logfile for filing logs. I want to make this HTTPClient a context manager, so that I can write with HTTPClient(url) as client: pass Actually, I overestimated the task: c

Re: nesting context managers

2011-12-20 Thread Rami Chowdhury
On Tue, Dec 20, 2011 at 14:15, Ulrich Eckhardt wrote: > Hi! > > Let us assume I had a class HTTPClient that has a socket for HTTP and a > logfile for filing logs. I want to make this HTTPClient a context manager, > so that I can write > >  with HTTPClient(url) as client: >      pass > > and reliab

nesting context managers

2011-12-20 Thread Ulrich Eckhardt
Hi! Let us assume I had a class HTTPClient that has a socket for HTTP and a logfile for filing logs. I want to make this HTTPClient a context manager, so that I can write with HTTPClient(url) as client: pass and reliably have both the socket and the logfile closed. The easy way is w