We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.


next( )

A file object is its own iterator, for example iter(f) returns f (unless f is closed). When a file is used as an iterator, typically in a for loop (for example, for line in f: print line), the file.next method is called repeatedly. This method returns the next input line, or raises StopIteration when EOF is hit. In order to make a for loop the most efficient way of looping over the lines of a file (a very common operation), the file.next method uses a hidden read-ahead buffer. As a consequence of using a read-ahead buffer, combining file.next with other file methods (like file.readline) does not work right. However, using file.seek to reposition the file to an absolute position will flush the read-ahead buffer. New in version 2.3.