Re: with statement and context managers

2011-08-04 Thread Steven D'Aprano
Thomas Rachel wrote: > Am 03.08.2011 04:15 schrieb Steven D'Aprano: [...] > > but to me that looks badly wrong. Surely the spam context manager > > object will exit after the first iteration, and always raise an > > exception on the second? But I don't quite understand context > > managers eno

Re: with statement and context managers

2011-08-03 Thread Thomas Rachel
Am 03.08.2011 04:15 schrieb Steven D'Aprano: > I'm not greatly experienced with context managers and the with > statement, so I would like to check my logic. > > Somebody (doesn't matter who, or where) stated that they frequently > use this idiom: > > spam = MyContextManager(*args) > for ham in m

Re: with statement and context managers

2011-08-02 Thread Nobody
On Wed, 03 Aug 2011 12:15:44 +1000, Steven D'Aprano wrote: > I'm not greatly experienced with context managers and the with statement, so > I would like to check my logic. > > Somebody (doesn't matter who, or where) stated that they frequently use this > idiom: > > spam = MyContextManager(*args)

Re: with statement and context managers

2011-08-02 Thread Jack Diederich
On Tue, Aug 2, 2011 at 10:15 PM, Steven D'Aprano wrote: > I'm not greatly experienced with context managers and the with statement, so > I would like to check my logic. > > Somebody (doesn't matter who, or where) stated that they frequently use this > idiom: > > spam = MyContextManager(*args) > fo

with statement and context managers

2011-08-02 Thread Steven D'Aprano
I'm not greatly experienced with context managers and the with statement, so I would like to check my logic. Somebody (doesn't matter who, or where) stated that they frequently use this idiom: spam = MyContextManager(*args) for ham in my_iter: with spam: # do stuff but to me that l