You can just say
for col in row: total += int(col)
For instance:
import csv from StringIO import StringIO total = 0 for row in csv.reader(StringIO("1,2,3,4")): for col in row: total += int(col) print total
The reason you can do this is because csv.reader returns a simple list for each line, so you can iterate over it like any other list in Python.
However, in your case, since you know that you have a file with one line of integers separated by commas, you can make this a lot easier:
line = open("ints.txt").read().split(",") total = sum(int(i) for i in line)
source share