reading from sys.stdin
Michael Bentley
michael at jedimindworks.com
Thu Apr 12 04:39:02 EDT 2007
On Apr 12, 2007, at 3:20 AM, 7stud wrote:
> I can't break out of the for loop in this example:
>
> ------
> import sys
>
> lst = []
> for line in sys.stdin:
> lst.append(line)
> break
>
> print lst
> -----------
>
> But, I can break out of the for loop when I do this:
>
> ---------
> import sys
>
> lst = []
> for line in open("aaa.txt"):
> lst.append(line)
> break
>
> print lst
> ----------
>
> Why doesn't break work in the first example?
My guess is because you've not entered an EOF. Try entering ^D (or
if you're on Windows I think it's ^Z) while using your first example
and see what it does.
More information about the Python-list
mailing list