如何在 Python 中打开二进制数据文件并将值一次读回long
一个结构。我现在有这样的东西,但我认为这会继续覆盖idList
,我想附加到它,所以我最终得到long
了文件中所有值的元组 -
file = open(filename, "rb")
try:
bytes_read = file.read(struct.calcsize("=l"))
while bytes_read:
# Read 4 bytes(long integer)
idList = struct.unpack("=l", bytes_read)
bytes_read = file.read(struct.calcsize("=l"))
finally:
file.close()