Parsing a string representing a float *with an exponent* in Python

Posted by Lucas on Stack Overflow See other posts from Stack Overflow or by Lucas
Published on 2010-05-12T22:40:54Z Indexed on 2010/05/12 22:44 UTC
Read the original article Hit count: 180

Filed under:

Hi,

I have a large file with numbers in the form of 6,52353753563E-7. So there's an exponent in that string. float() dies on this.

While I could write custom code to pre-process the string into something float() can eat, I'm looking for the pythonic way of converting these into a float (something like a format string passed somewhere). I must say I'm surprised float() can't handle strings with such an exponent, this is pretty common stuff.

I'm using python 2.6, but 3.1 is an option if need be.

© Stack Overflow or respective owner

Related posts about python