[Tutor] How to select particular lines from a text

R. Alan Monroe amonroe at columbus.rr.com
Sat Dec 4 18:51:00 CET 2004

> Name:
> City:
> xxxxxxxxxxxxxxxxxxxx
> xxxxxxxxxxxxxxxxxxxx

> Characterstics of this text:
> 1. This text is divided into blocks and every block
> start with 'Name'.  The number of lines after this
> identifier is random. 


> 1. mark the identifier i need and select all the lines
> after that identifier until it hits a new line or
> another name identifier. 

A "while" loop was invented for those times in life where you don't
know in advance how many times you want to repeat something.

while line != "Name:":
#once this loop exits, you know you've found the first "Name:" line

while line != "Name:":
      bigfile.readline() #keep reading every line upto the NEXT one
      do stuff here

More information about the Tutor mailing list