I process one file: skip the header (comment), process the first line, process other lines.
f = open(filename, 'r')
# skip the header
next(f)
# handle the first line
line = next(f)
process_first_line(line)
# handle other lines
for line in f:
process_line(line)
If line = next(f)
is replaced with line = f.readline()
, it will encounter the error.
ValueError: Mixing iteration and read methods would lose data
Therefore, I would like to know the differences among next(f)
, f.readline()
and f.next()
in Python?