next line (data parsing)
Scott David Daniels
Scott.Daniels at Acm.Org
Thu Jan 17 00:01:04 EST 2008
robleachza at gmail.com wrote:
> Hi there,
> I'm struggling to find a sensible way to process a large chuck of
> data--line by line, but also having the ability to move to subsequent
> 'next' lines within a for loop. I was hoping someone would be willing
> to share some insights to help point me in the right direction. This
> is not a file, so any file modules or methods available for files
> parsing wouldn't apply.
>
> I can iterate over each line by setting a for loop on the data object;
> no problem. But basically my intension is to locate the line "Schedule
> HOST" and progressively move on to the 'next' line, parsing out the
> pieces I care about, until I then hit "Total", then I resume to the
> start of the for loop which locates the next "Schedule HOST".
if you can do:
for line in whatever:
...
then you can do:
source = iter(whatever)
for intro in source:
if intro.startswith('Schedule '):
for line in source:
if line.startswith('Total'):
break
process(intro, line)
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list