Re: [Tutor] Yielding from a with block

2015-05-29 Thread Laura Creighton
In a message of Fri, 29 May 2015 14:13:16 +0100, Oscar Benjamin writes: >Python 2.7.2 (1.8+dfsg-2, Feb 19 2012, 19:18:08) >[PyPy 1.8.0 with GCC 4.6.2] > >$ pypy gencm.py >Entering >End of program > >The __exit__ method was not called at all under pypy. Even if I don't >keep a reference to g outsid

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Mark Lawrence
On 29/05/2015 15:23, Steven D'Aprano wrote: On Thu, May 28, 2015 at 10:16:00AM +0200, Peter Otten wrote: As interesting as this may be does it really belong on the tutor mailing list? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language.

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Steven D'Aprano
On Fri, May 29, 2015 at 03:01:50PM +0100, Oscar Benjamin wrote: > On 29 May 2015 at 14:29, Steven D'Aprano wrote: > > On Thu, May 28, 2015 at 10:16:00AM +0200, Peter Otten wrote: > > > >> Even if you limit yourself to CPython there is another effect: the order of > >> execution may not meet one's

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Steven D'Aprano
On Thu, May 28, 2015 at 10:16:00AM +0200, Peter Otten wrote: > Even if you limit yourself to CPython there is another effect: the order of > execution may not meet one's expectations/requirements: No, wait, forget everything I said in my previous post. This is *clearly* a case where our expecta

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Oscar Benjamin
On 29 May 2015 at 14:29, Steven D'Aprano wrote: > On Thu, May 28, 2015 at 10:16:00AM +0200, Peter Otten wrote: > >> Even if you limit yourself to CPython there is another effect: the order of >> execution may not meet one's expectations/requirements: > > [snip example] > > That's an interesting ex

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Steven D'Aprano
I have to think further on most of your post, but for the last point: On Fri, May 29, 2015 at 02:13:16PM +0100, Oscar Benjamin wrote: > Now run the same under pypy: > > $ pypy --version > Python 2.7.2 (1.8+dfsg-2, Feb 19 2012, 19:18:08) > [PyPy 1.8.0 with GCC 4.6.2] > > $ pypy gencm.py > Enteri

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Steven D'Aprano
On Thu, May 28, 2015 at 10:16:00AM +0200, Peter Otten wrote: > Even if you limit yourself to CPython there is another effect: the order of > execution may not meet one's expectations/requirements: [snip example] That's an interesting example, and I can't tell if that's a problem with your (and

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Oscar Benjamin
On 29 May 2015 at 13:38, Steven D'Aprano wrote: > > Otherwise I stand by my earlier position that you are misinterpreting > what it means to exit a with block. Pausing it to yield is not an exit. > > I did an experiment, where I tried to break the finalisation > guarantee using break, return and r

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Steven D'Aprano
On Thu, May 28, 2015 at 10:46:26AM +0100, Oscar Benjamin wrote: > I'm sure you understand the fundamental difference between calling a > function and yielding inside a with statement: when calling a function > the new frame is *appended* to the call stack keeping the current > frame and all of its

Re: [Tutor] Yielding from a with block

2015-05-28 Thread Oscar Benjamin
On 28 May 2015 at 09:16, Peter Otten <__pete...@web.de> wrote: > ...but the obvious route is of course > >> It's usually fairly trivial to rearrange things so that this doesn't >> happen: >> >> def wrap_header_footer(fin): >> yield htbegin >> for linelist in csv.reader(fin): >> yiel

Re: [Tutor] Yielding from a with block

2015-05-28 Thread Oscar Benjamin
On 28 May 2015 at 03:12, Steven D'Aprano wrote: > On Wed, May 27, 2015 at 11:27:46PM +0100, Oscar Benjamin wrote: > >> I'm just wondering what other people think about this. Should code >> like make_lines below be discouraged? >> >> > def make_lines(): >> > with open('co2-sample.csv') as co2:

Re: [Tutor] Yielding from a with block

2015-05-28 Thread Peter Otten
Oscar Benjamin wrote: > On 23 May 2015 at 10:52, Peter Otten <__pete...@web.de> wrote: > I'm just wondering what other people think about this. Should code > like make_lines below be discouraged? >> def make_lines(): >> with open('co2-sample.csv') as co2: >> yield htbegin >>

Re: [Tutor] Yielding from a with block

2015-05-27 Thread Steven D'Aprano
On Wed, May 27, 2015 at 11:27:46PM +0100, Oscar Benjamin wrote: > I'm just wondering what other people think about this. Should code > like make_lines below be discouraged? > > > def make_lines(): > > with open('co2-sample.csv') as co2: > > yield htbegin > > for linelist in cs

Re: [Tutor] Yielding from a with block

2015-05-27 Thread Cameron Simpson
On 27May2015 23:27, Oscar Benjamin wrote: On 23 May 2015 at 10:52, Peter Otten <__pete...@web.de> wrote: import csv I'm just wondering what other people think about this. Should code like make_lines below be discouraged? In my opinion, no. def make_lines(): with open('co2-sample.csv')

[Tutor] Yielding from a with block

2015-05-27 Thread Oscar Benjamin
On 23 May 2015 at 10:52, Peter Otten <__pete...@web.de> wrote: > import csv > > I'm just wondering what other people think about this. Should code like make_lines below be discouraged? > def make_lines(): > with open('co2-sample.csv') as co2: > yield htbegin > for linelist in