continue/else functionality
Chris Richard Adams
chrisa at ASPATECH.COM.BR
Mon Mar 12 15:27:39 EST 2001
I have a script that reads lines out of a text file. The first line in
the file serves as a "flag-line" stating whether or not the file should
be read: 1 yes, 0 no. The rest of the file contains data lines to be
read. How can I get my script to read on the first line and upon getting
a 1 go back to the for, get the next line and read the rest from there?
For example, I tried:
for line in f.readlines():
datalist = string.split(line)
if datalist[0][0] == 1:
continue
elif datalist[0][0] == 0:
break
## Do a bunch of string manipulation here...
As the documentation states, from 4.4 of the tutorial "The continue
statement, also borrowed from C, continues with the next iteration of
the loop. "
Here it doesn't seem to be doing that...its continuing with the current
iteration of for.
Upon reading this first line, I need to go back and get the next line to
go on...
suggestions???
Thanks!
Chris
More information about the Python-list
mailing list