Reading Fortran Ascii output using python

Heli hemla21 at gmail.com
Mon Oct 31 13:20:18 EDT 2016


Hi all, 

I am trying to read an ascii file written in Fortran90 using python. I am reading this file by opening the input file and then reading using:

inputfile.readline()

On each line of the ascii file I have a few numbers like this:

line 1: 1
line 2: 1000.834739 2000.38473 3000.349798 
line 3: 1000 2000 5000.69394 99934.374638 54646.9784

The problem is when I have more than 3 numbers on the same line such as line 3, python seems to read this using two reads. This makes the above example will be read like this:

line 1: 1
line 2: 1000.834739 2000.38473 3000.349798 
line 3: 1000 2000 5000.69394 
line 4: 99934.374638 54646.9784

How can I fix this for each fortran line to be read correctly using python?

Thanks in Advance for your help, 
 



More information about the Python-list mailing list