To all:
I have curious if someone can help me understand the error: ValueError: invalid literal for float(). I am getting this when I am passing a text file to a list then trying to convert this list to float values.
a = open("input.txt","r")
lines = a.readlines()
b = map(float, lines)
What is odd, at least to me is that when I process:
print repr(lines[0])
I get:
'0.000\t0.000...\t0.000\t0.000\n'
and
print type(lines[0])
I get:
<type 'str'>
I don't understand therefore why the map(float, lines) does not work correctly. Am I using this function incorrectly? Looking at the documentation the map function is given as: map(function, iterable, ...). Is a list not iterable?
Also if someone could explain this error/point me in the direction of an explanation for this error I would greatly appreciate it.
Thanks in advance for help with this question.
0.000\t0.000...\t0.000\nis all one line? If so, then I'd assume that's what's being passed intofloat()and it can't convert. Seems like you'd need to split it up into individual float values. Is that the case?\tbeing displayed as whitespace (i.e. an actual tab character). That's all one string literal, not a bunch of shorter ones, I'm guessing.