2024-04-26 19:07:58 发布
网友
如果我理解正确的话,Python使用的float与C中的double相同,所以是8字节。有没有办法让这一切顺利?从Python导出4字节浮点,这将是与C++中4字节浮点相同的表示形式吗?你知道吗
struct模块处理这个问题。你知道吗
struct
>>> import struct >>> struct.pack("f", 3.14) # 4-byte float b'\xc3\xf5H@' >>> struct.pack("g", 3.14) # 8-byte double b'\x1f\x85\xebQ\xb8\x1e\t@'
有关如何控制结果的结束性的更多信息,请参见文档。你知道吗
arrayPython模块允许您一次性转储浮点数组:
array
import array def dump_numbers(filename, numbers): with open(filename, 'wb') as fp: array.array('f', numbers).tofile(fp)
struct
模块处理这个问题。你知道吗有关如何控制结果的结束性的更多信息,请参见文档。你知道吗
array
Python模块允许您一次性转储浮点数组:相关问题 更多 >
编程相关推荐