skip item in list for loop

2006-04-14 Thread Jacob Rael
I am new to python and I love it. I am hacking a file. I want to not print a line if it contains the word 'pmos4_highv'. I also don't want to print the next line. The following code works but it smells bad and just doesn't look right. I was reading about generators. If I was using one, I could do

Re: skip item in list for loop

2006-04-14 Thread Diez B. Roggisch
Jacob Rael schrieb: I am new to python and I love it. I am hacking a file. I want to not print a line if it contains the word 'pmos4_highv'. I also don't want to print the next line. The following code works but it smells bad and just doesn't look right. I was reading about generators. If I

Re: skip item in list for loop

2006-04-14 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 20:33 +0200, Diez B. Roggisch escreveu: def read_lines(inFile): fg = iter(inFile) for line in fg: if pmos4_highv in line: fg.next() else: yield line Just be aware that the fb.next() line can raise an StopIteration

Re: skip item in list for loop

2006-04-14 Thread Diez B. Roggisch
Felipe Almeida Lessa schrieb: Em Sex, 2006-04-14 às 20:33 +0200, Diez B. Roggisch escreveu: def read_lines(inFile): fg = iter(inFile) for line in fg: if pmos4_highv in line: fg.next() else: yield line Just be aware that the fb.next()

Re: skip item in list for loop

2006-04-14 Thread Jacob Rael
Thanks for the suggestions. The solution I liked most was to prevent the lines from appearing in the first place!! -- http://mail.python.org/mailman/listinfo/python-list