named pipe input
Donn Cave
donn at u.washington.edu
Thu Sep 1 19:24:55 EDT 2005
In article <3gIRe.6091$O6.328317 at news3.tin.it>,
"max(01)*" <max2 at fisso.casa> wrote:
> i have some problems understanding following behaviour.
>
> consider this:
> $ cat file_input_3.pl
> #!/usr/bin/perl
>
> open MIAPIPE, "una_pipe";
>
> while ($riga = <MIAPIPE>)
...
> $ cat file_input_3.py
> #!/usr/bin/python
>
> import sys
>
> MIAPIPE = open("una_pipe", "r")
>
> for riga in MIAPIPE:
...
> BUT if i try to do the same with the python code, something different
> happens: i have to type ALL the lines on console #2 and complete the cat
> command (ctrl-d) before seeing the lines echoed on console #1.
Seems to me something like this came up here
not long ago. It turns out that
for line in file:
doesn't do the same thing as Perl's
while ($line = <file>)
If you use file.readline() instead (in a loop,
of course, I think you'll get the data one line
at a time, but "in file" apparently reads the
whole file first. That's what I vaguely remember,
I don't use it myself.
Donn Cave, donn at u.washington.edu
More information about the Python-list
mailing list