Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'subject:file': 0.07; 'line:': 0.09; 'literal': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'otherwise:': 0.16; 'subject:Text': 0.16; 'wrote:': 0.18; 'memory': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'question': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; 'follows': 0.31; 'received:google.com': 0.35; 'really': 0.36; 'skip:o 20': 0.38; 'how': 0.40; 'skip:u 10': 0.60; 'july': 0.63; 'more': 0.64; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=ErKZnJLELSQHcmstQ6abHC9BDXdqvi64pJU23zfqWCM=; b=N9nEp5D0iJbspkXeDU8QDJUEPaXH9GzTnxiIQBtLs/MVnHIxQQM6HoGDx4zzQCERWB VpSpZbUS7Jmc3V0Qx8uQXvFZnY3aZNvIh8IwFicCxRryYUlrM2DgXonMsKIncFI4HMgd 4LuOeqzJZQHwjp7lCdB4DqoMwTajyVZP85unQ083i3gZWZlJuYYQqR2ZZsPjo3Dll5+v BqPQw7/gm17UOVm0qCz6VFGa3dBcL9lqvQxuOKj0VzZyTFRu+NjfPWoy8jeWlH6Nip4c uSG+iQxzTpSZKLLLeyUyMSLjhs9uVx3jTAUp3b6y7LivvXWbZpt0k46b94NkVG3Q3/K6 FlkA== X-Received: by 10.152.42.171 with SMTP id p11mr9194080lal.79.1372796946507; Tue, 02 Jul 2013 13:29:06 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <08ae2828-1532-47b6-a9cb-208549189467@googlegroups.com> <8ea32ea7-2cee-4e61-8cbd-066721d88d4a@googlegroups.com> From: Joshua Landau Date: Tue, 2 Jul 2013 21:28:26 +0100 Subject: Re: Parsing Text file To: Tobiah Content-Type: text/plain; charset=UTF-8 Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372796949 news.xs4all.nl 15984 [2001:888:2000:d::a6]:48865 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49653 On 2 July 2013 20:50, Tobiah 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 = []