Re: [Tutor] parsing a "chunked" text file

2010-03-19 Thread Karim Liateni
Hello, Thanks both of you for these useful information. Regards Karim Hugo Arts wrote: On Thu, Mar 18, 2010 at 12:54 PM, Stefan Behnel wrote: Karim Liateni, 04.03.2010 01:23: Yes, a *big* difference in the true sense of the word. Your code (assuming you meant to write "... for line in ..

Re: [Tutor] parsing a "chunked" text file

2010-03-18 Thread Hugo Arts
On Thu, Mar 18, 2010 at 12:54 PM, Stefan Behnel wrote: > Karim Liateni, 04.03.2010 01:23: > > Yes, a *big* difference in the true sense of the word. Your code (assuming > you meant to write "... for line in ..." ) evaluates the entire list > comprehension before returning from the call. Steven's c

Re: [Tutor] parsing a "chunked" text file

2010-03-18 Thread Stefan Behnel
Karim Liateni, 04.03.2010 01:23: Steven D'Aprano wrote: def skip_blanks(lines): """Remove leading and trailing whitespace, ignore blank lines.""" for line in lines: line = line.strip() if line: yield line Is there a big difference to write your first functions as below because I am not familia

Re: [Tutor] parsing a "chunked" text file

2010-03-03 Thread Karim Liateni
Hello Steven, Is there a big difference to write your first functions as below because I am not familiar with yield keyword? def skip_blanks(lines): """Remove leading and trailing whitespace, ignore blank lines.""" return [line.strip() in lines if line.strip()] I tried to write as wel

Re: [Tutor] parsing a "chunked" text file

2010-03-02 Thread Steven D'Aprano
On Tue, 2 Mar 2010 05:22:43 pm Andrew Fithian wrote: > Hi tutor, > > I have a large text file that has chunks of data like this: > > headerA n1 > line 1 > line 2 > ... > line n1 > headerB n2 > line 1 > line 2 > ... > line n2 > > Where each chunk is a header and the lines that follow it (up to the >

Re: [Tutor] parsing a "chunked" text file

2010-03-02 Thread spir
On Mon, 1 Mar 2010 22:22:43 -0800 Andrew Fithian wrote: > Hi tutor, > > I have a large text file that has chunks of data like this: > > headerA n1 > line 1 > line 2 > ... > line n1 > headerB n2 > line 1 > line 2 > ... > line n2 > > Where each chunk is a header and the lines that follow it (up

Re: [Tutor] parsing a "chunked" text file

2010-03-02 Thread Christian Witts
Andrew Fithian wrote: Hi tutor, I have a large text file that has chunks of data like this: headerA n1 line 1 line 2 ... line n1 headerB n2 line 1 line 2 ... line n2 Where each chunk is a header and the lines that follow it (up to the next header). A header has the number of lines in the chun

[Tutor] parsing a "chunked" text file

2010-03-02 Thread Andrew Fithian
Hi tutor, I have a large text file that has chunks of data like this: headerA n1 line 1 line 2 ... line n1 headerB n2 line 1 line 2 ... line n2 Where each chunk is a header and the lines that follow it (up to the next header). A header has the number of lines in the chunk as its second field. I