[Numpy-discussion] Another question on reading from binary FORTRAN file

Mark Bakker markbak at gmail.com
Tue Mar 10 11:05:06 EDT 2009


Thanks, Mike.
This seems to be a really easy way.
One more question.
It turns out my file also contains a character string of 16 characters.
I tried
np.fromfile(fd,np.str,16)
But that gives an error.
Can I read a characterstring with fromfile?
I know, I can read with fd.read, but I am wondering if there is an
option for fromfile as well.
Thanks,

Mark

> From: Michael Gilbert <michael.s.gilbert at gmail.com>
> fid = open( 'fort.out' , 'r' )
> junk = numpy.fromfile( fid , numpy.int , 1 )
> integer = numpy.fromfile( fid, numpy.int , 1 )
> junk = numpy.fromfile( fid , numpy.int , 2 )
> floats = numpy.fromfile( fid , numpy.float , 16 )



More information about the NumPy-Discussion mailing list