Lazy "for line in f" ?
alexandre.ferrieux at gmail.com
Mon Jul 23 11:18:35 CEST 2007
On Jul 23, 10:33 am, Duncan Booth <duncan.bo... at invalid.invalid>
> The extra buffering means that iterating over a file is about 3 times
> faster than repeatedly calling readline.
> while 1:
> line = f.readline()
> if not line:
> for line in f:
Surely you'll notice that the comparison is spoilt by the fact that
the readline version needs an interpreted test each turn around.
A more interesting test would be the C-implemented iterator, just
calling fgets() (the thin layer policy) without extra 8k-blocking.
More information about the Python-list