[Tutor] delete strings from specificed words

YU Bo tsu.yubo at gmail.com
Wed Jan 10 23:16:47 EST 2018


Hi,
On Thu, Jan 11, 2018 at 11:40:35AM +1100, Cameron Simpson wrote:
>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
>[...]
>>```
[...]
>>
>>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.

En.., the text is  multi-string from str(something) within python.

>
>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.

Yes, i test your method  and it will come to my intend, but maybe cast
a few of other steps.

I think that the method will offer a similar ways to solve others issues.
I personally like peter's method: text.partition("diff  --git")[0].strip()

Thanks,
Bo
>
>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