2

I get output files from very old Fortran programs, which look like:

 0.81667E+00  -0.12650E+01  -0.69389E-03
 0.94381E+00  -0.11985E+01  -0.11502E+00
 0.96064E+00  -0.11333E+01  -0.17616E+00
 0.10202E+01  -0.12435E+01  -0.93917E-01
 0.10026E+01  -0.10904E+01  -0.15108E+00
 0.90516E+00  -0.11030E+01  -0.19139E+00
 0.98624E+00  -0.11598E+01  -0.22970E+00

Is it possible to read this in Python and convert the numbers to "normal" floats?

2
  • What did you try? What errors did you get when you tried it? Commented Feb 25, 2010 at 18:23
  • @Werner - This has nothing to do with fortran. This is an example of a "normal" (as normal as one can get) data file. Commented Feb 25, 2010 at 20:18

2 Answers 2

4
Python 2.6.1 (r261:67515, Jul  7 2009, 23:51:51) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> float('-0.69389E-03')
-0.00069388999999999996
Sign up to request clarification or add additional context in comments.

Comments

2
>>> line="0.81667E+00  -0.12650E+01  -0.69389E-03"
>>> map(float,line.split())
[0.81667000000000001, -1.2649999999999999, -0.00069388999999999996]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.