时间:2020-11-04 11:33:57 | 栏目:Python代码 | 点击:次
问题
有二进制文件中保存了 20 亿个 2 Bytes 的数,需将其读出,每 20000 个数作图,拟合后输出结果。
解决
# -*- coding: utf-8 -*-
"""
@author: kurrrr
"""
import struct
def main():
data_file = open('run0035.bin', 'rb')
data_temp = data_file.read(2)
data_short, = struct.unpack('h', data_temp)
print(data_short)
if __name__ == '__main__':
main()
总结
关于 struct 模块中的 format 具体可在官网上找到。