Python 2.7 mixing iteration and read methods would lose data

The problem is that you are using next and readline on the same file. As the docs say:

. As a consequence of using a read-ahead buffer, combining next() with other file methods (like readline()) does not work right.

The fix is trivial: replace next with readline.

Leave a Comment