with open('./file/test.txt', 'wb+') as f:
    for i in nums:
        s = struct.pack('i', i)
        f.write(s)

 读:

    nums = []
    with open('./file/2010.txt', 'rb+') as f:
        for i in range(len1):
            data = f.read(4)
            elem = struct.unpack('i', data)[0]
            nums.append(elem)

 注意:struct返回的元组

 python读写入二进制文件

def readFile(url):
    res = []
    with open(url, 'rb+') as f:
        while True:
            data = f.read(8)
            if not data:
                break
            elem = struct.unpack('2i', data)
            res.append(elem)
            
    return res

python读写入二进制文件

 

 

 

相关文章:

  • 2021-07-19
  • 2021-11-11
  • 2021-10-06
  • 2021-12-01
  • 2021-08-19
  • 2021-06-26
  • 2021-07-21
猜你喜欢
  • 2021-09-30
  • 2021-09-16
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
相关资源
相似解决方案