[Tutor] How to skip to next line in for loop
Kent Johnson
kent37 at tds.net
Fri May 2 12:55:21 CEST 2008
On Fri, May 2, 2008 at 3:55 AM, Roel Schroeven
<rschroev_nospam_ml at fastmail.fm> wrote:
> Shouldn't it even be 'line = f.next()'?
Wow, I think Brain Stormer should get a prize. I'm not sure what the
prize is, but his short program has elicited incomplete and inaccurate
answers from three of the top posters to this list! I *think* this is
a complete answer:
f = open('file.txt',r)
for line in f:
if line.rstrip() == "3":
line = f.next()
print line
break # put this in if there is only one line you want to print
f.close()
...awaiting any further corrections :-)
Kent
More information about the Tutor
mailing list