使用python编写双精度二进制文件

使用python编写双精度二进制文件,python,double-precision,Python,Double Precision,如何使用Python编写双精度文件和二进制文件?我目前正在做以下工作,但它给了我单精度文件: #!/usr/bin/env python import struct data =[2.3715231753176,9.342983274982732] output_file = "test.dat" out_file = open(output_file,"wb") s = struct.pack('f'*len(data), *data) out_file.write(s) out_fil

如何使用Python编写双精度文件和二进制文件?我目前正在做以下工作,但它给了我单精度文件:

#!/usr/bin/env python

import struct

data =[2.3715231753176,9.342983274982732]

output_file = "test.dat"
out_file = open(output_file,"wb")
s = struct.pack('f'*len(data), *data)
out_file.write(s)
out_file.close()

使用
d
写入双精度浮点:

s = struct.pack('d'*len(data), *data)
f
仅为单精度。请参阅
struct
模块文档部分:

对于
'f'
'd'
转换代码,压缩表示使用IEEE 754 binary32(对于
'f'
)或binary64(对于
'd'
)格式,而不考虑平台使用的浮点格式


使用
d
写入双精度浮点:

s = struct.pack('d'*len(data), *data)
f
仅为单精度。请参阅
struct
模块文档部分:

对于
'f'
'd'
转换代码,压缩表示使用IEEE 754 binary32(对于
'f'
)或binary64(对于
'd'
)格式,而不考虑平台使用的浮点格式


您错误地使用了格式字符串。要使用双精度,请使用“d”而不是“f”。有关格式字符的列表,请参阅。

您错误地使用了格式字符串。要使用双精度,请使用“d”而不是“f”。有关格式字符的列表,请参见