Iteration on file reading
Paul McGuire
ptmcg at austin.rr.com
Fri Oct 3 23:57:44 EDT 2003
Try a generator. This will just read a line at a time.
-- Paul
<code>
from sys import stdin
def lineReader( strm ):
while 1:
yield strm.readline().rstrip("\n")
for f in lineReader( stdin ):
print ">>> " + f
</code>
"Paul Watson" <pwatson at redlinec.com> wrote in message
news:3f7ca9ea$1_1 at themost.net...
> for line in sys.stdin:
>
> Does this statement cause all of stdin to be read before the loop begins?
>
> I may need to read several GB and I do not want to swamp the machine's
> memory.
>
>
More information about the Python-list
mailing list