Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #96296
| From | alister <alister.nospam.ware@ntlworld.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: textfile: copy between 2 keywords |
| Date | 2015-09-10 19:41 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <mssmcl$hgu$1@speranza.aioe.org> (permalink) |
| References | <13d875f0-ae8d-43de-85b4-c943a0e7f5e2@googlegroups.com> <mssehl$pb8$1@dont-email.me> <a41d94a3-5be0-4b95-98ad-f7a00520b984@googlegroups.com> |
On Thu, 10 Sep 2015 12:11:55 -0700, wxjmfauth wrote:
>>>> s = """1, 2, 3, 4
> ... #keyword1 ... 3, 4, 5, 6 ... 2, 3, 4, 5 ... #keyword2 ... 4, 5, 6
> ,7"""
>>>> s[s.find('keyword1') + len('keyword1'):s.find('keyword2') - 1]
> '\n3, 4, 5, 6\n2, 3, 4, 5\n'
>>>> #or s[s.find('keyword1') + len('keyword1') + 1:s.find('keyword2') -
>>>> 2]
> '3, 4, 5, 6\n2, 3, 4, 5'
>>>>
split works well
as a simple 1 liner (well 2 if you include the string setup)
>>>a="crap word1 more crap word1 again word2 still more crap"
>>>a.split('word1',1)[1].split('word2')[0]
' more crap word1 again '
--
All bad precedents began as justifiable measures.
-- Gaius Julius Caesar, quoted in "The Conspiracy of
Catiline", by Sallust
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
textfile: copy between 2 keywords Gerald <schweiger.gerald@gmail.com> - 2015-09-10 04:18 -0700
Re: textfile: copy between 2 keywords Steven D'Aprano <steve@pearwood.info> - 2015-09-10 22:10 +1000
Re: textfile: copy between 2 keywords Jussi Piitulainen <harvesting@makes.email.invalid> - 2015-09-10 16:47 +0300
Re: textfile: copy between 2 keywords Vlastimil Brom <vlastimil.brom@gmail.com> - 2015-09-10 16:33 +0200
Re: textfile: copy between 2 keywords Jussi Piitulainen <harvesting@makes.email.invalid> - 2015-09-10 18:48 +0300
Re: textfile: copy between 2 keywords Christian Gollwitzer <auriocus@gmx.de> - 2015-09-10 19:29 +0200
Re: textfile: copy between 2 keywords wxjmfauth@gmail.com - 2015-09-10 12:11 -0700
Re: textfile: copy between 2 keywords alister <alister.nospam.ware@ntlworld.com> - 2015-09-10 19:41 +0000
csiph-web