beginner's python help

Maggie la.foma at gmail.com
Sun Sep 6 09:00:16 CEST 2009


code practice:

test = open ("test.txt", "r")
readData = test.readlines()
#set up a sum
sum = 0;
for item in readData:
	sum += int(item)
print sum

test file looks something like this:

34
23
124
432
12

when i am trying to compile this it gives me the error: invalid
literal for int() with base 10

i know a lot of people get this and it usually means that you try to
cast a string into an integer and this string does not really contain
a “digit”..so I am just not sure how to correct it in this case...

thanks for your input



More information about the Python-list mailing list