[Tutor] Text matching

Gardner, Dean Dean.Gardner at barco.com
Thu May 3 15:46:10 CEST 2007


 Thanks I will try that. Your help is very much appreciated.


Dean Gardner
Test Engineer 
Barco
Bonnington Bond, 2 Anderson Place, Edinburgh EH6 5NP, UK
Tel + 44 (0) 131 472 5731 Fax + 44 (0) 131 472 4799
www.barco.com 
dean.gardner at barco.com 


-----Original Message-----
From: Kent Johnson [mailto:kent37 at tds.net] 
Sent: 03 May 2007 14:39
To: Gardner, Dean
Cc: tutor at python.org
Subject: Re: [Tutor] Text matching

Gardner, Dean wrote:
> Here is a test sample of what I have: This currently correctly 
> identifies the start and the end of the changelog entries and I can 
> identify the requested item records. What I am struggling with at 
> present is to how to create records of the full changelog entries for 
> each of the found items.
> 
> Again any help greatly appreciated.
> 
> 
> uid = "000028.txt"
> 
> 
> file = open("C:\projects\SuiteSpecification\Notes\ChangeLog.txt")
> 
> output = file.readlines()
> changeLogList = []
> itemList = []
> for strOut in output:
> 
>     if "----" in strOut:
>         changeLogStart = 1
>     itemList.append(strOut)       
>     if "Reviewed:" in strOut:
>         changeLogStart=0
> for item in itemList:
>     if uid in item:
>         print item

I usually solve problems like this by pulling multiple lines from the
file within the loop. Something like this:
f = open('...ChangeLog.txt')
try:
   while True:
     line = f.next()
     if line.startswith('----'):
       line1 = line
       line2 = f.next()
       line3 = f.next()
       line4 = f.next()
       # Do something to process the lines
     line = f.next()
except StopIteration:
   pass

The basic idea is that you can collect multiple lines by calling
f.next() explicitly inside the loop.

Kent


DISCLAIMER:
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.


More information about the Tutor mailing list