I am trying to read a huge number of lines from standard input using python.
more hugefile.txt | python readstdin.py
The problem is that the program freezes as soon as I read only one line.
print sys.stdin.read(8) exit(1)
This prints the first 8 bytes, but then I expect it to complete, but it will never happen. I think this is not just reading the first bytes, but an attempt to read the entire file in memory.
Same problem with sys.stdin.readline ()
What I really want to do is, of course, read all the lines, but with a buffer, so I do not have enough memory.
I am using python 2.6
Martin
source share