Alan thanks for the response;
> Message: 8 > Date: Sun, 1 Apr 2007 08:54:02 +0100 > From: "Alan Gauld" <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Another parsing question > To: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; format=flowed; charset="iso-8859-1"; > reply-type=original > > > "Jay Mutter III" <[EMAIL PROTECTED]> wrote > >> for line in s: >> jay = patno.findall(line) >> jay2 = "".join(jay[0]) >> print jay2 >> >> and it prints fine up until line 111 which is a line that had >> previously returned [ ] since a number didn't exist on that line and >> then exits with > >> IndexError: list index out of range > > Either try/catch the exception or add an > if not line: continue # or return a default string > >> And as long as i am writing, how can I delete a return at the end of >> a line if the line ends in a certain pattern? >> >> For instance, if line ends with the abbreviation No. > > if line.endswith(string): line = line.rstrip() > For some reason this never works for me; i am using an intel imac with OS X 10.4.9 which has python 2.3.5 inp = open('test.txt','r') s = inp.readlines() for line in s: if line.endswith('No.'): line = line.rstrip() print line and it never ever removes the line feed. (These are unix \r according to Text wrangler) I am beginning to think that it is a problem with readlines. But then i thought well why not inp = open('test.txt','r') s = inp.readlines() for line in s: if line.endswith('No.'): line += s.next() print line, however that doesn't work either which leads me to believe that it is me and my interpretation of the above. Thanks Jay >> I want to join the current line with next line. >> Are lists immutable or can they be changed? > > lists can be changed, tuples cannot. > > HTH, > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.freenetpages.co.uk/hp/alan.gauld > > > > > ------------------------------ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest, Vol 38, Issue 1 > ************************************ _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor