[Tutor] delete strings from specificed words

Cameron Simpson cs at cskk.id.au
Wed Jan 10 19:40:35 EST 2018


On 09Jan2018 22:20, YU Bo <tsu.yubo at gmail.com> wrote:
>The text i will working as follow:
>
>```text
[...]
>diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
>index a789f952b3e9..443892dabedb 100644
[...]
>+++ b/tools/perf/util/util.c
[...]
>```
>In fact, this is a patch from lkml,my goal is to design a kernel podcast
>for myself to focus on what happened in kernel. I have crawled the text
>with python and want to remove strings from *diff --git*, because reading
>the git commit above, i have a shape in head.
>
>I have tried split(), replace(), but i have no idea to deal with it.

Do you have the text as above - a single string - or coming from a file? I'll 
presume a single string.

I would treat the text as lines, particularly since the diff markers etc are 
all line oriented.

So you might write something like this:

  interesting = []
  for line in the_text.splitlines():
    if line.startswith('diff --git '):
      break
    interesting.append(line)

Now the "interesting" list has the lines you want.

There's any number of variations on that you might use, but that should get you 
going.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Tutor mailing list