Why is "for line in f" faster than readline()

Alexandre Ferrieux alexandre.ferrieux at gmail.com
Thu Jul 26 14:13:57 EDT 2007


Hi,

In a recent thread I discovered why the "for line in f" idiom was not
suitable for live sources (pipes, sockets, tty).
The reason is that it uses buffering on input, blocking on a full
buffer read before anything.
When I asked why it did it this way, the answer came up that it made
it faster.

Now, *why* is such buffering gaining speed over stdio's fgets(), which
already does input buffering (though in a more subtle way, which makes
it still usable with pipes etc.) ?

-Alex




More information about the Python-list mailing list