A
Alexandre Ferrieux
Hi,
I'm a total newbie in Python, but did give quite a try to the
documentation before coming here.
Sorry if I missed the obvious.
The Tutorial says about the "for line in f" idiom that it is "space-
efficient".
Short of further explanation, I interpret this as "doesn't read the
whole file before spitting out lines".
In other words, I would say "lazy". Which would be a Good Thing, a
much nicer idiom than the usual while loop calling readline()...
But when I use it on the standard input, be it the tty or a pipe, it
seems to wait for EOF before yielding the first line.
So, is it lazy or not ? Is there some external condition that may
trigger one behavior or the other ? If not, why is it said "space
efficient" ?
TIA,
-Alex
I'm a total newbie in Python, but did give quite a try to the
documentation before coming here.
Sorry if I missed the obvious.
The Tutorial says about the "for line in f" idiom that it is "space-
efficient".
Short of further explanation, I interpret this as "doesn't read the
whole file before spitting out lines".
In other words, I would say "lazy". Which would be a Good Thing, a
much nicer idiom than the usual while loop calling readline()...
But when I use it on the standard input, be it the tty or a pipe, it
seems to wait for EOF before yielding the first line.
So, is it lazy or not ? Is there some external condition that may
trigger one behavior or the other ? If not, why is it said "space
efficient" ?
TIA,
-Alex