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


Groups > comp.lang.python > #49653

Re: Parsing Text file

References <08ae2828-1532-47b6-a9cb-208549189467@googlegroups.com> <b3gnnaFbe60U1@mid.individual.net> <8ea32ea7-2cee-4e61-8cbd-066721d88d4a@googlegroups.com> <I9GAt.794$ct1.646@newsfe07.iad>
From Joshua Landau <joshua.landau.ws@gmail.com>
Date 2013-07-02 21:28 +0100
Subject Re: Parsing Text file
Newsgroups comp.lang.python
Message-ID <mailman.4123.1372796949.3114.python-list@python.org> (permalink)

Show all headers | View raw


On 2 July 2013 20:50, Tobiah <toby@tobiah.org> wrote:
> How do we know whether we have Sometext?
> If it's really just a literal 'Sometext', then
> just print that when you hit maskit.
>
> Otherwise:
>
>
> for line in open('file.txt').readlines():
>
>         if is_sometext(line):
>                 memory = line
>
>         if line == 'maskit':
>                 print memory

My understanding of the question follows more like:

# Python 3, UNTESTED

memory = []
for line in open('file.txt').readlines():
    if line == 'maskit':
        print(*memory, sep="")

    elif line:
        memory.append(line)

    else:
        memory = []

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


Thread

Parsing Text file sas429s@gmail.com - 2013-07-02 11:45 -0700
  Re: Parsing Text file Neil Cerutti <neilc@norwich.edu> - 2013-07-02 19:24 +0000
    Re: Parsing Text file sas429s@gmail.com - 2013-07-02 12:30 -0700
      Re: Parsing Text file Tobiah <toby@tobiah.org> - 2013-07-02 12:50 -0700
        Re: Parsing Text file Neil Cerutti <neilc@norwich.edu> - 2013-07-02 20:12 +0000
          Re: Parsing Text file sas429s@gmail.com - 2013-07-02 13:28 -0700
            Re: Parsing Text file Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-02 21:56 +0100
            Re: Parsing Text file Denis McMahon <denismfmcmahon@gmail.com> - 2013-07-03 00:55 +0000
        Re: Parsing Text file Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-02 21:28 +0100

csiph-web