reading from sys.stdin
bbxx789_05ss at yahoo.com
Fri Apr 13 11:36:47 CEST 2007
On Apr 13, 3:13 am, Michael Hoffman <cam.ac... at mh391.invalid> wrote:
> 7stud wrote:
> > I assume all input is buffered by default, so I'm not sure how it
> > explains things to say that input from sys.stdin is buffered.
> The difference with sys.stdin is that it has indeterminate length until
> you signal EOF. I believe you'd get the same problem reading from, say,
> a named pipe.
Couldn't you say the same thing about a file you are iterating over?
> >> I typed many lines, but lst contains only one item, as expected. Same as
> >> your regular file example: the file contains many lines, but only the
> >> first goes into the list.
> > Interesting example--not as I expected! But there is a difference in
> > the two examples isn't there? When you iterate over a file, the whole
> > file isn't put into an internal buffer first, is it?
> It is if the file is smaller than the buffer size.
How is that relevant?
> >> This should be f = iter(raw_input,"") and this will end in a EOFError
> >> and stop on blank line. So you need a wrapper
> > Why a wrapper?
> Because without a wrapper you'll get EOFError, while the file iterator
> would ordinarily give you StopIteration.
Did you run my example? Did you get an error? I don't get an error.
More information about the Python-list