Parsing text

Bengt Richter bokr at oz.net
Tue Dec 20 09:59:00 EST 2005


On 19 Dec 2005 15:15:10 -0800, "sicvic" <morange.victor at gmail.com> wrote:

>I was wondering if theres a way where python can read through the lines
>of a text file searching for a key phrase then writing that line and
>all lines following it up to a certain point, such as until it sees a
>string of "---------------------"
>
>Right now I can only have python write just the line the key phrase is
>found in.
>
This sounds like homework, so just a (big) hint: have a look at itertools
dropwhile and takewhile. The solution is potentially a one-liner, depending
on your matching criteria (e.g., case-sensitive fixed string vs regular expression).

Regards,
Bengt Richter



More information about the Python-list mailing list