Nick Rout wrote: > Thanks Carl, called it stool, short for searchtool > > however > > [nick@www nick]$ cat /usr/samba/wp/huntly/21B-1260.txt |./stool > Traceback (innermost last): > File "./stool", line 23, in ? > elif ls[1] == "Mortgage": > IndexError: list index out of range
shouldn't happen if the file was like you described. Have you got extra spaces or hidden characters? Are the lines terminated by \n or \r\n? If they are \r\n, change the -1 in the first line of the for loop to -2. >>------------------------------------------------- >>#!/usr/bin/env python >> >>import sys, string >> >>lines = sys.stdin.readlines() >> >>len = len(lines) >> >>str = "" >>for i in range(len): >> line = lines[i][:-1] >> #print line >> if line == "Proprietor": >> if str != "": >> print str >> str = "" >> continue >> if line == "": >> continue >> ls = string.split(line) >> if ls[0] == "Identifier": >> str = str + ","+ls[1] >> elif ls[1] == "Mortgage": >> str = str + ","+ls[0] >> str = str + ","+string.join(ls[3:]) >> else: >> str = line >>print str >>-------------------------------------------------- >> > > > -- > Nick Rout > Barrister & Solicitor > Christchurch, NZ > Ph +64 3 3798966 > Fax + 64 3 3798853 > http://www.rout.co.nz > >
