想检查我写的这个脚本来读取 Fortran 二进制文件

Want to check this script I wrote to read a Fortran binary file

我正在从事一个需要我阅读 Fortran 二进制文件的项目。据我了解,Fortran 会自动将 4 字节的页眉和页脚放入每个文件中。因此,我想在读取文件之前从文件中删除第一个和最后一个 4 个字节。这会成功吗?

a = open("foo",rb)
b = a.seek(4,0)

x = np.fromfile(b.seek(4,2),dtype='float64')

读取整个文件然后在每一端切掉 4 个字节可能更容易:

a = open("foo","rb")
data = a.read()
a.close()

x = np.fromstring(data[4:-4], dtype='float64')

类似问题见How to read part of binary file with numpy?