skip item in list "for loop"

Felipe Almeida Lessa felipe.lessa at gmail.com
Fri Apr 14 14:40:08 EDT 2006


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
exception that would otherwise be caught by the for loop. If you have
any resources that need to be cleaned up, try...finally is you friend.

-- 
Felipe.




More information about the Python-list mailing list