reading from sys.stdin
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Thu Apr 12 04:47:46 EDT 2007
En Thu, 12 Apr 2007 05:20:58 -0300, 7stud <bbxx789_05ss at yahoo.com>
escribió:
> 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
> -----------
Python 2.5.1c1 (r251c1:54692, Apr 5 2007, 09:19:18) [MSC v.1310 32 bit
(Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
py> import sys
py> lst = []
py> for line in sys.stdin:
... lst.append(line)
... break
...
hola
que
tal
como
estan
^Z
py> print lst
['hola\n']
-----------
I typed many lines, but lst contains only one item, as expected. Same as
your regular file example: the file contains many lines, but only the
first goes into the list.
--
Gabriel Genellina
More information about the Python-list
mailing list