[Numpy-discussion] convert FORTRAN exponential format text to float

Thomas Kirk Gamble tkg@lanl....
Wed Sep 29 09:09:30 CDT 2010

I need to convert numbers read from a text file to floating point.  The
numbers are in the format 1.538D-06 (written by a FORTRAN application)
and have varying amounts of whitespace between them from line to line.
The function fromstring() deals with the whitespace just fine but
'dtype=float' doesn't correctly convert the data.  It sees every thing
up to the 'D' and ignores the rest(I assume expecting an 'e' to indicate
the exponential).  I was able to get around this using re.sub() to
change the 'D' to 'e' in the string before using fromstring(), but I was
wondering if python has any way to directly read this data as float?
Google didn't find an answer.

More information about the NumPy-Discussion mailing list