Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41505
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-03-19 07:20 -0700 |
| Message-ID | <f9e61b45-759f-4286-a639-9fb826ec5597@googlegroups.com> (permalink) |
| Subject | Need help in extracting lines from word using python |
| From | razinzamada@gmail.com |
I'm currently trying to extract some data between 2 lines of an input file using Python. the infile is set up such that there is a line -START- where I need the next 10 lines of code if and only if the -END- condition occurs before the next -START-. The -START- line occurs many times before the -END-. Heres a general example of what I mean:
blah
blah
-START-
10 lines I DONT need
blah
-START-
10 lines I need
blah
blah
-END-
blah
blah
-START-
10 lines I dont need
blah
-START-
.... and so on and so forth
so far I have only been able to get the -START- + 10 lines for every iteration, but am at a total loss when it comes to specifying the condition to only write if the -END- condition comes before another -START- condition. I'm a bit of a newb, so any help will be greatly appreciated.
heres the code I have for printing the -START- + 10 lines:
in = open('input.log')
out = open('output.txt', 'a')
lines = in.readlines()
for i, line in enumerate(lines):
if (line.find('START')) > -1:
out.write(line)
out.write(lines[i + 1])
out.write(lines[i + 2])
out.write(lines[i + 3])
out.write(lines[i + 4])
out.write(lines[i + 5])
out.write(lines[i + 6])
out.write(lines[i + 7])
out.write(lines[i + 8])
out.write(lines[i + 9])
out.write(lines[i + 10])
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Need help in extracting lines from word using python razinzamada@gmail.com - 2013-03-19 07:20 -0700
Re: Need help in extracting lines from word using python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-19 14:41 +0000
Re: Need help in extracting lines from word using python razinzamada@gmail.com - 2013-03-19 23:13 -0700
Re: Need help in extracting lines from word using python Dave Angel <davea@davea.name> - 2013-03-19 10:54 -0400
Re: Need help in extracting lines from word using python razinzamada@gmail.com - 2013-03-19 23:14 -0700
Re: Need help in extracting lines from word using python razinzamada@gmail.com - 2013-03-19 23:14 -0700
csiph-web