My input file has the form:
5.0, 1000.0, 100000000000000.0, 115.2712, 230.538, 345.796, 461.0408,
1.053E-09, 1.839E-09, 1.632E-10, 1.959E-12, 4.109, 3.683, 3.586, 3.650
where every number is essentially in a line.
What I want to do is read all the floats, and then append only columns 7 through 10 to an array.
Here's what I've written:
T=[]
with open("test.txt", "r") as file1:
for line in file1.readlines():
f_list = [float(i) for i in line.split(",")]
T.append(float(f_list[7]))
T.append(float(f_list[8]))
T.append(float(f_list[9]))
T.append(float(f_list[10]))
When I run the above I get:
ValueError: could not convert string to float:
I think there's something wrong with the float(i)
part, but I can't find a way around it.
I've seen people having similar problems here, but none of the fixes I've tried so far have helped. Any help is greatly appreciated.
float()
, it fails.