I'm facing a problem in converting str
to float
. I do like in this post but this time it's not working because I have numbers in this format:
5.50000e+000 5.50000e+001 5.50000e+002 5.50000e+003
If I change the format (for example using 5.5 55 550 5500
) it works fine. The Traceback states only:
Traceback (most recent call last):
File "phresREADER.py", line 27, in <module>
tra = float(stri)
ValueError: could not convert string to float:
What can I do? Is there a specific command?
my code is:
my_line = f.readline()
avg_energySTR = [str(i) for i in my_line.split(' ')]
for stri in avg_energySTR:
tra = float(stri)
when I print avg_energySTR I get
['5.50000e+000', '5.50000e+001', '5.50000e+002', '5.50000e+003', '\n']
THE ANSWER IS IN THE KOJIRO'S COMMENT