Reading 4 byte integers from binary file in Python

后端 未结 2 804
甜味超标
甜味超标 2021-02-06 12:55

I have a some sets of binary files (some are potentially large (100MB)) that contain 4 byte integers.

Can anyone supply a code snippet to show how to extract each 4 byte

2条回答
  •  再見小時候
    2021-02-06 13:41

    Check out the NumPy fromfile function. You provide a simple type annotation about the data to be read, and the function efficiently reads it into a NumPy ndarray object.

    import numpy as np
    np.fromfile(file_name, dtype='

    You can change dtype to reflect size and byte order as well. See here for some examples.

提交回复
热议问题