Warning about "for line in file:"

Neil Schemenauer nas at python.ca
Sat Feb 16 12:32:28 EST 2002


Aldo Cortesi wrote:
> Actually this has nothing to do with iterators, or a "read
> cache".

It does.

> iter(file) creates a line iterator that does the
> same thing as file.readline() every time .next() is called,
> until it reaches the end of the file.

It does not.  iter(file) calls file.xreadlines().  xreadlines()
internally calls readlines(CHUNKSIZE).

> But file.readline(), just like any other file read,
> starts reading at the _current seek position_ of the file. 

True but irrelevant to the discussion at hand.

  Neil




More information about the Python-list mailing list