I am trying to read numbers from a file in python. The file contains ONLY numbers. ALl numbers are decimal!! As asked, this is the file contents: 25 4 2 6 7
I get this error:
Traceback (most recent call last):
File "readfile.py", line 18, in <module>
a.append(int(data[i]))
ValueError: invalid literal for int() with base 10: 'f'"
This is my code:
check=0
while(check!=1):
file=raw_input("Plase state the file name:")
print "\n"
try:
check=1
fo=open(file,"r",1)
except IOError:
print "NO such file or directory"
check=0
data=0
a=[]
i=0
for line in file:
data=line.split()
print data
a.append(int(data[i]))
i=i+1
print a
fo.close()
idoes what you think it does. it increments for each line, not looping on the split.