reading from sys.stdin
Diez B. Roggisch
deets at nospam.web.de
Sun Apr 15 17:04:52 EDT 2007
>> Steve Holden +44 150 684 7255 +1 800 494 3119
>> Holden Web LLC/Ltd http://www.holdenweb.com
>> Skype: holdenweb http://del.icio.us/steve.holden
>> Recent Ramblings http://holdenweb.blogspot.com
>
> I just typed in 700 lines of text, and the iteration hasn't begun
> yet. Should I keep going?
>
Well, I'm not sure how much of a programmer you are if you don't get the
idea of writing a _program_ to do the typing....
-------- a.py -----------
import sys
counter = 0
try:
while True:
s = str(counter) + '\n'
counter += len(s)
sys.stdout.write(s)
except IOError:
sys.stderr.write(s)
------- b.py ------------
import sys
lst = []
for line in sys.stdin:
lst.append(line)
break
print lst
-----------------
Besides that, a little bit of logic thinking should make clear that
having to wait till EOF won't work too much for piping programs that
produce continously output with possibly terabytes of data. Even under
modern memory constraints...
Diez
More information about the Python-list
mailing list