[Tutor] Another parsing question
Alan Gauld
alan.gauld at btinternet.com
Sun Apr 1 09:54:02 CEST 2007
"Jay Mutter III" <jmutter at uakron.edu> 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()
> 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
More information about the Tutor
mailing list