Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Neil Cerutti Newsgroups: comp.lang.python Subject: Re: Parsing Text file Date: 2 Jul 2013 20:12:55 GMT Organization: Norwich University Lines: 40 Message-ID: References: <08ae2828-1532-47b6-a9cb-208549189467@googlegroups.com> <8ea32ea7-2cee-4e61-8cbd-066721d88d4a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: individual.net D0jrmB57DpgkFDd9AciLvgMaFHFKAx6EM7p8Bw9ehaU3p8kl58 Cancel-Lock: sha1:GoDAiWHax1QRR7dSHC0gL3rkzUY= User-Agent: slrn/0.9.9p1/mm/ao (Win32) Xref: csiph.com comp.lang.python:49651 On 2013-07-02, Tobiah wrote: > On 07/02/2013 12:30 PM, sas429s@gmail.com wrote: >> Somemore can be anything for instance: >> >> Sometext >> mail >> maskit >> >> Sometext >> rupee >> dollar >> maskit >> >> and so on.. >> >> Is there a way I can achieve this? > > 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 Tobiah's solution fits what little we can make of your problem. My feeling is that you've simplified your question a little too much in hopes that it would help us provide a better solution. Can you provide more context? -- Neil Cerutti