Re: Does fileinput.input() read STDIN all at once?
- From: Jonathan Gardner <jgardner.jonathangardner.net@xxxxxxxxx>
- Date: Tue, 18 Dec 2007 11:24:05 -0800 (PST)
On Dec 18, 5:55 am, Adam Funk <a24...@xxxxxxxxxxxxx> wrote:
I'm using this sort of standard thing:
for line in fileinput.input():
do_stuff(line)
and wondering whether it reads until it hits an EOF and then passes
lines (one at a time) into the variable line. This appears to be the
behaviour when it's reading STDIN interactively (i.e. from the
keyboard).
As a test, I tried this:
for line in fileinput.input():
print '**', line
and found that it would print nothing until I hit Ctl-D, then print
all the lines, then wait for another Ctl-D, and so on (until I pressed
Ctl-D twice in succession to end the loop).
There is probably a 1024 byte buffer. Try filling it up and see if you
get something before you hit CTRL-D.
Otherwise, the writers have to flush the buffer if they want a line to
be sent before the buffer fills up. C++ endl would do this, I believe,
in addition to printing '\n'.
Note that terminals (what you get if you are typing from the command
line) are terminals and behave quite differently than open files.
Is it possible to configure this to pass each line of input into line
as it comes?
It's up to the writer to flush the buffers. There's not much you can
do, so just learn to live with it.
It sounds like you want to write some kind of interactive program for
the terminal. Do yourself a favor and use curses or go with a full-
blown GUI.
.
- Follow-Ups:
- Re: Does fileinput.input() read STDIN all at once?
- From: Adam Funk
- Re: Does fileinput.input() read STDIN all at once?
- References:
- Does fileinput.input() read STDIN all at once?
- From: Adam Funk
- Does fileinput.input() read STDIN all at once?
- Prev by Date: Re: Changing intobject to use int rather than long
- Next by Date: Re: lotus nsf to mbox
- Previous by thread: Does fileinput.input() read STDIN all at once?
- Next by thread: Re: Does fileinput.input() read STDIN all at once?
- Index(es):
Relevant Pages
|