Re: Question about yield

2015-11-16 Thread Steven D'Aprano
On Sun, 15 Nov 2015 01:37 pm, fl wrote: > Hi, > I have read a couple of tutorial on yield. The following code snippet > still gives me a shock. I am told yield is a little like return. I only > see one yield in the tutorial examples. Here it has two yields. And there > are three variables followin

Re: Question about yield

2015-11-14 Thread Chris Angelico
On Sun, Nov 15, 2015 at 1:37 PM, fl wrote: > Or are there some high relevant tutorial on this? > Start here: https://docs.python.org/3/tutorial/index.html ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Question about yield

2015-11-14 Thread fl
Hi, I have read a couple of tutorial on yield. The following code snippet still gives me a shock. I am told yield is a little like return. I only see one yield in the tutorial examples. Here it has two yields. And there are three variables following keyword yield. I have not tried debug function t

Re: A question about yield

2010-11-08 Thread Simon Brunning
On 7 November 2010 18:14, Chris Rebert wrote: > On Sun, Nov 7, 2010 at 9:56 AM, chad wrote: >> But what happens if the input file is say 250MB? Will all 250MB be >> loaded into memory at once? > > No. As I said, the file will be read from 1 line at a time, on an > as-needed basis; which is to say

Re: A question about yield

2010-11-07 Thread Chris Rebert
On Sun, Nov 7, 2010 at 9:56 AM, chad wrote: > On Nov 7, 9:47 am, Chris Rebert wrote: >> On Sun, Nov 7, 2010 at 9:34 AM, chad wrote: >> >> > #!/usr/local/bin/python >> >> > import sys >> >> > def construct_set(data): >> >    for line in data: >> >        lines = line.splitlines() >> >        for

Re: A question about yield

2010-11-07 Thread chad
On Nov 7, 9:47 am, Chris Rebert wrote: > On Sun, Nov 7, 2010 at 9:34 AM, chad wrote: > > > > > > > #!/usr/local/bin/python > > > import sys > > > def construct_set(data): > >    for line in data: > >        lines = line.splitlines() > >        for curline in lines: > >            if curline.stri

Re: A question about yield

2010-11-07 Thread Chris Rebert
On Sun, Nov 7, 2010 at 9:34 AM, chad wrote: > #!/usr/local/bin/python > > import sys > > def construct_set(data): >    for line in data: >        lines = line.splitlines() >        for curline in lines: >            if curline.strip(): >                key = curline.split(' ') >                va

Re: A question about yield

2010-11-07 Thread chad
On Nov 7, 9:34 am, chad wrote: > I have an input file named 'freq' which contains the following data > > 123 0 > > 133 3 > 146 1 > 200 0 > 233 10 > 400 2 > > Now I've attempted to write a script that would take a number from the > standard input and then > have the program return the number in the

A question about yield

2010-11-07 Thread chad
I have an input file named 'freq' which contains the following data 123 0 133 3 146 1 200 0 233 10 400 2 Now I've attempted to write a script that would take a number from the standard input and then have the program return the number in the input file that is closest to that input file. #!/us