It tells you that the line contains text that can't be converted to an
int
.
strip()
will only remove leading and trailing white spaces.
To handle such cases you can use
try
-
except
:
for line in read:
try:
num = int(line.strip())
aList.append(num)
except:
print "Not a number in line " + line
Note that I have changed the
while
loop to a
for
loop on the file object because that is more efficient.