Reading 32 bit signed ieee 754 floating points from a binary file with python?

前端 未结 3 1051
傲寒
傲寒 2020-12-30 00:35

I have a binary file which is simple a list of signed 32 bit ieee754 floating point numbers. They are not separated by anything, and simply appear one after another until EO

相关标签:
3条回答
  • 2020-12-30 01:04
    struct.unpack('f', file.read(4))
    

    You can also unpack several at once, which will be faster:

    struct.unpack('f'*n, file.read(4*n))
    
    0 讨论(0)
  • 2020-12-30 01:11

    Take a peek at struct.unpack. Something like the following might work...

    f = struct.unpack('f', data_read)
    
    0 讨论(0)
  • 2020-12-30 01:15
    import struct
    (num,) = struct.unpack('f', f.read(4))
    
    0 讨论(0)
提交回复
热议问题