Float in Python

Solved
erickvand -  
 erickvand -
Hello,

I have a small problem in Python when I write (in a loop on i and ii):
float(lignes[i].strip().split(" ")[ii]), it doesn't return anything,

with lignes[i].strip().split(" ")[ii] being a string containing decimal numbers.

Is it because there are commas instead of points in my string that it doesn't work or is it for another reason?

Thank you in advance
Configuration: Windows XP Internet Explorer 6.0

1 answer

fiddy Posted messages 441 Registration date   Status Contributor Last intervention   1 847
 
Hello,
Indeed, if you convert a number that is not a float, it won't work.
You can replace commas with points by doing:
float(lignes[i].strip().split(" ")[ii].replace(',','.'))

Best regards
--

Google is your friend
8
erickvand
 
Thank you very much,

Indeed, it works better!

++
0