Is it safe to read some lines with readline() and also use for line in file, and is it guaranteed to use the same file position?
Usually, I want to disregard the first line (headers), so I do this:
FI = open("myfile.txt")
FI.readline() # disregard the first line
for line in FI:
my_process(line)
FI.close()
Is this safe, i.e., is it guaranteed that the same file position variable is used while iterating lines?
No, it isn’t safe:
You could use
next()to skip the first line here. You should also test forStopIteration, which will be raised if the file is empty.