How to grab the lines AFTER a matched line in python

Posted by toofly on Stack Overflow See other posts from Stack Overflow or by toofly
Published on 2011-01-04T15:19:53Z Indexed on 2011/01/04 15:54 UTC
Read the original article Hit count: 203

Filed under:
|
|
|

Hi All,

I am an amateur using Python on and off for some time now. Sorry if this is a silly question, but I was wondering if anyone knew an easy way to grab a bunch of lines if the format in the input file is like this:

" Heading 1

Line 1

Line 2

Line 3

Heading 2

Line 1

Line 2

Line 3 "

I won't know how many lines are after each heading, but I want to grab them all. All I know is the name, or a regular expression pattern for the heading.

The only way I know to read a file is the "for line in file:" way, but I don't know how to grab the lines AFTER the line I'm currently on. Hope this makes sense, and thanks for the help!

© Stack Overflow or respective owner

Related posts about python

Related posts about text