How do I go about opening a binary data file in Python and reading back the values one long
at a time, into a struct. I have something like this at the moment but I think this will keep overwriting idList
, I want to append to it, so I end up with a tuple of all the long
values in the file -
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()
Thanks.