I have a text file called "foo.txt", with a list of numbers, one on each line, for example:
0.094195
0.216867
0.326396
0.525739
0.592552
0.600219
0.637459
0.642935
0.662651
0.657174
0.683461
I now want to read these numbers into a Python list. My code to do this is as follows:
x = []
file_in = open('foo.dat', 'r')
for y in file_in.read().split('\n'):
x.append(float(y))
But this gives me the error:
ValueError: could not convert string to float
What am I doing wrong?