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


Groups > comp.lang.python > #41513

Re: Need help in extracting lines from word using python

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python.': 0.02; 'subject:help': 0.07; 'backwards': 0.09; 'lines:': 0.09; 'specifying': 0.09; 'subject:using': 0.09; '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; 'example': 0.23; 'proprietary': 0.23; '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; 'to:addr:python-list': 0.33; 'another': 0.33; 'text': 0.34; 'loss': 0.34; 'there': 0.35; 'next': 0.35; 'but': 0.36; 'does': 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; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'help': 0.40; 'end': 0.40; 'your': 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; 'received:74.208': 0.71; 'forth': 0.75; 'apart.': 0.84
Date Tue, 19 Mar 2013 10:54:24 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130221 Thunderbird/17.0.3
MIME-Version 1.0
To python-list@python.org
Subject Re: Need help in extracting lines from word using python
References <f9e61b45-759f-4286-a639-9fb826ec5597@googlegroups.com>
In-Reply-To <f9e61b45-759f-4286-a639-9fb826ec5597@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:vCf56ZJDxH8TlC1zNsfIBS1BSSoDxL4otelc9SoJLmY C/3E8+5LG/nReue39Tisgisksboev1kd2fA4Loo51Ts+/4umVC 2e92RbiljHDrzdfxqf0qSXSZf3HKhoBtUPyEsY99zNE7XrvB31 0ymeldIgqdIFnbktDrzAdRgcvkhQJMjuAxRP9iOaqQzVXbk/y8 vHw0GJ3vfkKuqLzYuv7yeoK8oJT1TJDV4pUKcel7r4hqwuVTAo TNpEPK7cS096xGqmIrAzXkD89L7hOPTg3dEI7PG5H7Af0uynIo rkD1/k0oYvtT8HmkPXM3SVQtVHdoRxlPRKgbVmAAhHvKDQSWA= =
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>
Newsgroups comp.lang.python
Message-ID <mailman.3513.1363704886.2939.python-list@python.org> (permalink)
Lines 67
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1363704886 news.xs4all.nl 6864 [2001:888:2000:d::a6]:55631
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41513

Show key headers only | View raw


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