stdio EOF ?
Erik Max Francis
max at alcyone.com
Fri Aug 9 15:25:03 EDT 2002
Jacek Generowicz wrote:
> Using "for line is stdin: ..." works if all the commands are in a file
> and I do
>
> cat command_file | filter.py | etc
>
> but in the "cat | filter.py" situation, it doesn't produce any output
> until C-d is sent.
>
> I guess I'm looking for a "while something(stdin)" or "while
> stdin.something" construct ...
The standard idiom for this is:
while 1:
line = file.readline()
if not line:
break
...
The .readline method of a file object returns a complete line (including
the trailing newline), or an empty string in the case of EOF.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/ \ There is nothing so subject to the inconstancy of fortune as war.
\__/ Miguel de Cervantes
Church / http://www.alcyone.com/pyos/church/
A lambda calculus explorer in Python.
More information about the Python-list
mailing list