Re: with statement

2012-04-19 Thread Ethan Furman
Ian Kelly wrote: On Thu, Apr 19, 2012 at 3:33 PM, Terry Reedy wrote: On 4/19/2012 1:15 PM, Kiuhnm wrote: A with statement is not at the module level only if it appears inside a function definition or a class definition. This is true, I believe, of all statements. Am I forgetting something?

Re: with statement

2012-04-19 Thread Ian Kelly
On Thu, Apr 19, 2012 at 3:33 PM, Terry Reedy wrote: > On 4/19/2012 1:15 PM, Kiuhnm wrote: >> >> A with statement is not at the module level only if it appears inside a >> function definition or a class definition. > > > This is true, I believe, of all statements. > >> Am I forgetting something? >

Re: with statement

2012-04-19 Thread Terry Reedy
On 4/19/2012 1:15 PM, Kiuhnm wrote: A with statement is not at the module level only if it appears inside a function definition or a class definition. This is true, I believe, of all statements. Am I forgetting something? Comprehensions (in Py3) and lambda expressions also introduce new loc

Re: with statement

2012-04-19 Thread Kiuhnm
On 4/19/2012 20:02, Jacob MacDonald wrote: On Thursday, April 19, 2012 10:15:23 AM UTC-7, Kiuhnm wrote: A with statement is not at the module level only if it appears inside a function definition or a class definition. Am I forgetting something? Kiuhnm That sounds about right to me. However,

Re: with statement

2012-04-19 Thread Jacob MacDonald
On Thursday, April 19, 2012 10:15:23 AM UTC-7, Kiuhnm wrote: > A with statement is not at the module level only if it appears inside a > function definition or a class definition. > Am I forgetting something? > > Kiuhnm That sounds about right to me. However, I haven't really used with's very mu

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

Re: with statement and standard library

2010-02-21 Thread Chris Rebert
On Sun, Feb 21, 2010 at 3:21 PM, John Nagle wrote: > nobrowser wrote: >> >> Hi.  The with statement is certainly nifty.  The trouble is, the >> *only* two documented examples how it can be used with the library >> classes are file objects (which I use all the time) and thread locks >> which I almo

Re: with statement and standard library

2010-02-21 Thread John Nagle
nobrowser wrote: Hi. The with statement is certainly nifty. The trouble is, the *only* two documented examples how it can be used with the library classes are file objects (which I use all the time) and thread locks which I almost never use. Yet there are many, many classes in the library whos

Re: with statement and standard library

2010-02-19 Thread Terry Reedy
On 2/19/2010 2:18 AM, nobrowser wrote: Hi. The with statement is certainly nifty. The trouble is, the *only* two documented examples how it can be used with the library classes are file objects (which I use all the time) and thread locks which I almost never use. Yet there are many, many class

Re: with statement and standard library

2010-02-19 Thread Robert Kern
On 2010-02-19 01:18 AM, nobrowser wrote: Hi. The with statement is certainly nifty. The trouble is, the *only* two documented examples how it can be used with the library classes are file objects (which I use all the time) and thread locks which I almost never use. Yet there are many, many cla

Re: with statement and standard library

2010-02-19 Thread alex23
nobrowser wrote: > Yet there are many, many classes in the > library whose use would be more elegant and readable if the with > statement could be employed.  Start with the connection objects in > httplib and you can probably come up with 10 others easily.  Maybe it > is the case that some of thes

Re: with statement for two files

2008-07-28 Thread greg
Diez B. Roggisch wrote: Paul Rubin wrote: > > use contextlib.nexted(). You mean contextlib.nested I guess. Although "nexted" is an intriguing-sounding word. I wonder what it could mean? -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: with statement for two files

2008-07-28 Thread Diez B. Roggisch
Paul Rubin wrote: > braver <[EMAIL PROTECTED]> writes: >> with open(src) as readin, open(dst,"w") as writin: # WRONG: comma >> doesn't work >> ... >> -- so that you have transactional safety for two file descriptors? > > use contextlib.nexted(). You mean contextlib.nested I guess. Didn't kno

Re: with statement for two files

2008-07-28 Thread Paul Rubin
braver <[EMAIL PROTECTED]> writes: > with open(src) as readin, open(dst,"w") as writin: # WRONG: comma > doesn't work > ... > -- so that you have transactional safety for two file descriptors? use contextlib.nexted(). -- http://mail.python.org/mailman/listinfo/python-list

Re: with statement for two files

2008-07-27 Thread Diez B. Roggisch
braver schrieb: Can open two files in a with statement: with open(src) as readin, open(dst,"w") as writin: # WRONG: comma doesn't work ... -- so that you have transactional safety for two file descriptors? The comma syntax doesn't work, but is there a way, except for with open(src) as read

Re: With Statement Contexts and Context Managers

2007-07-31 Thread G
Great thanks. On 7/31/07, Carsten Haese <[EMAIL PROTECTED]> wrote: > > On Tue, 2007-07-31 at 14:57 -0400, G wrote: > > Hi, > > > >Could somebody please point me to a good resource to read about > > the contexts, context managers, and with_statement > > > > There's PEP 343 at http://www.python.

Re: With Statement Contexts and Context Managers

2007-07-31 Thread Carsten Haese
On Tue, 2007-07-31 at 14:57 -0400, G wrote: > Hi, > >Could somebody please point me to a good resource to read about > the contexts, context managers, and with_statement > There's PEP 343 at http://www.python.org/dev/peps/pep-0343/. I don't know if that fits your definition of "good," but it