May-22-2020, 09:56 AM
(This post was last modified: May-22-2020, 09:56 AM by player1681.)
(May-22-2020, 09:41 AM)ibreeden Wrote: As the message says: data is not a float. And also as the message shows: data is a lot of floats. That is the problem. You have to convert the text lines one by one to float. I guess something like (untested):
for dataline in data: print(float(dataline))
Thanks for the answer, but I am afraid it doesn't work, since it seems to convert element to element, if the first row is 2.25, float(data[3])=5.0, aditionally, the error
Error:ValueError: could not convert string to float: '.'
appears, probably due to the fact that the code is converting each element by itself to float.EDIT:
with open('posx_mean_no_acoplo_tf_multiple.txt', 'r') as f: content = f.readlines() content = [x.strip() for x in content] [float(i) for i in content] print(content) type(content)seems to work