And it's not me. This is taken verbatim from Mark Lutz's book "Programming Python"
you have data.txt:
123
000
999
042
You have adder.py:
import sys
sum = 0
while True:
try:
line = raw_input()
except EORError:
break
else:
sum += int(line)
print sum
Now at the command line:
user@computer:~$cat data.txt | python adder.py
This is supposed to output 1164 instead I get:
Traceback (most recent call last):
File "adder.py", line 9, in <module>
sum += int( line )
ValueError: invalid literal for int() with base 10: ''
I've looked up int() and by its description this should work. I've also tried to run it with different commands, like:
python adder.py < data.txt
python sorter.py < data.txt | python adder.py
All give the same error. I'm using version 2.5.1
(The code is indented correctly, just doesn't show up that way here.)