Reading in strings -> numbers ??

Phil Austin phil at geog.ubc.ca
Sat Apr 29 06:17:37 CEST 2000


"Louis M. Pecora" <pecora at anvil.nrl.navy.mil> writes:

> Is there a Python "read-partner" for the write(string) function, e.g., 
> 
> fileobject.write(" %e %e %d" % (1.2, -3.5, 10))

You might want to check out Konrad Hinsen's  FortanFormat package
in ScientificPython:

http://starship.python.net/crew/hinsen/scientific.html

from FortranFormat import *
input=open('lemout1.dat','r')
format=FortranFormat('(f15.6,1x,f20.6)')
x=[]
c=[]

line=1
while(line):
    line=input.readline()
    getit=FortranLine(line,format)
    x.append(getit[0])
    c.append(getit[1])

Regards, Phil



More information about the Python-list mailing list