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