start reading from certain line
Diez B. Roggisch
deets at nospam.web.de
Wed Jul 9 06:53:19 EDT 2008
More information about the Python-list mailing list
Wed Jul 9 06:53:19 EDT 2008
- Previous message (by thread): start reading from certain line
- Next message (by thread): start reading from certain line
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
antar2 wrote:
> I am a starter in python and would like to write a program that reads
> lines starting with a line that contains a certain word.
> For example the program starts reading the program when a line is
> encountered that contains 'item 1'
>
>
> The weather is nice
> Item 1
> We will go to the seaside
> ...
>
> Only the lines coming after Item 1 should be read
Start reading each line, and skip them until your criterion matches. Like
this:
def line_skipper(predicate, line_iterable):
for line in line_iterable:
if predicate(line):
break
for line in line_iterable:
yield line
Diez
- Previous message (by thread): start reading from certain line
- Next message (by thread): start reading from certain line
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list