Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41571

Re: Need help in extracting lines from word using python

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <razinzamada@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'subject:help': 0.07; 'backwards': 0.09; 'lines:': 0.09; 'specifying': 0.09; 'subject:using': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'subject:python': 0.11; 'files.': 0.13; 'file,': 0.15; '"from': 0.16; '-1:': 0.16; 'easier.': 0.16; 'guessing': 0.16; 'iteration,': 0.16; 'wrote:': 0.17; 'specify': 0.17; 'input': 0.18; 'trying': 0.21; 'bit': 0.21; 'not,': 0.21; 'assumes': 0.22; 'default,': 0.22; 'occurs': 0.22; 'cc:2**0': 0.23; 'example': 0.23; 'proprietary': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'appreciated.': 0.26; 'am,': 0.27; 'coding': 0.27; 'possibility': 0.27; 'lines': 0.28; 'skip:( 20': 0.28; "i'm": 0.29; 'code': 0.31; '(and': 0.32; 'file': 0.32; 'says': 0.33; 'extract': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'text': 0.34; 'loss': 0.34; 'thanks': 0.34; 'received:209.85': 0.35; 'there': 0.35; 'next': 0.35; 'but': 0.36; 'does': 0.37; 'received:209': 0.37; 'far': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'description': 0.39; 'where': 0.40; 'help': 0.40; 'end': 0.40; 'your': 0.60; 'from:no real name:2**0': 0.60; 'save': 0.61; 'subject:Need': 0.61; 'first': 0.61; 'between': 0.63; 'times': 0.63; 'email addr:gmail.com': 0.63; 'behavior': 0.64; 'dont': 0.64; 'total': 0.65; 'subject': 0.66; 'forth': 0.75; '2013': 0.84; 'apart.': 0.84; 'angel': 0.93
X-Received by 10.50.151.205 with SMTP id us13mr78149igb.2.1363760094946; Tue, 19 Mar 2013 23:14:54 -0700 (PDT)
Newsgroups comp.lang.python
Date Tue, 19 Mar 2013 23:14:54 -0700 (PDT)
In-Reply-To <mailman.3513.1363704886.2939.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=199.63.142.252; posting-account=GeTYGQoAAABfBC2zuW1DVIGJ9smkbUcQ
References <f9e61b45-759f-4286-a639-9fb826ec5597@googlegroups.com> <mailman.3513.1363704886.2939.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 199.63.142.252
MIME-Version 1.0
Subject Re: Need help in extracting lines from word using python
From razinzamada@gmail.com
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.3548.1363760721.2939.python-list@python.org> (permalink)
Lines 147
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1363760721 news.xs4all.nl 6893 [2001:888:2000:d::a6]:57142
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41571

Show key headers only | View raw


Thanks DAVE

On Tuesday, March 19, 2013 8:24:24 PM UTC+5:30, Dave Angel wrote:
> On 03/19/2013 10:20 AM, razinzamada@gmail.com wrote:
> 
> > I'm currently trying to extract some data between 2 lines of an input file
> 
> 
> 
> Your subject line says "from word".  I'm only guessing that you might 
> 
> mean Microsoft Word, a proprietary program that does not, by default, 
> 
> save text files.  The following code and description assumes a text 
> 
> file, so there's a contradiction.
> 
> 
> 
> 
> 
> > 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:
> 
> >
> 
> 
> 
> In other words, you want to scan for -END-, then go backwards to -START- 
> 
> and use the first ten of the lines between?  Try coding it that way, and 
> 
> perhaps it'll be easier.
> 
> 
> 
> You also need to consider (and specify behavior for) the possibility 
> 
> that start and end are less than 10 lines apart.
> 
> 
> 
> > 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])
> 
> 
> 
>      or just        out.write(lines[i:i+11)     to write out all 11 of them.
> 
> >
> 
> 
> 
> 
> 
> -- 
> 
> DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


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