Trying to take input from stdin and convert to integer for sum
<p>Very new to Python.
Trying to take inputs from stdin in the form of numbers ex. 416 2876 2864 8575 9784 and convert to int for sum of all using a loop.</p>

<p>Having a terrible time just converting to int for use in a loop. Would like to get a hint on the integer issue and then try to solve myself. Was trying to test my code to print the integers after conversion.</p>

<p>currently have:</p>

<pre><code>import sys
s=sys.stdin
n=(sys.stdin.split())
while (int(n) &gt;= 1):
    print(n)
</code></pre>

<p>If you want to read from <em>stdin</em> and cast to int just iterate over stdin and split then cast each int and <em>sum</em> :</p>

<pre><code>~$ cat test.py
import sys


print(sum(int(i) for sub  in sys.stdin for i in sub.split()))

padraic@dell:~$ printf "416 2876 2864 8575 9784\n123 456 789 120"|python test.py
26003
</code></pre>

<p>Or using map:</p>

<pre><code>import sys
print(sum(sum(map(int, sub.split())) for sub  in sys.stdin))
</code></pre>

<p>Or just call read and split.</p>

<pre><code>import sys
print(sum(map(int, sys.stdin.read().split())))
</code></pre>

python