Does fileinput.input() read STDIN all at once?

Adam Funk a24061 at ducksburg.com
Wed Dec 19 15:09:38 EST 2007


On 2007-12-18, Jonathan Gardner wrote:

>> 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.

Thanks; I'm looking into the buffering question.


> 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.

No, I'm really interested in reading the input from files!

This just came up because I was trying to test the program by giving
it no filename arguments and typing sample input.



More information about the Python-list mailing list