转自:Python 读写字节数据

使用模式为 rb 或 wb 的 open() 函数来读取或写入二进制数据。比如:

# Read the entire file as a single byte string
with open('somefile.bin', 'rb') as f:
    data = f.read()
 
# Write binary data to a file
with open('somefile.bin', 'wb') as f:
    f.write(b'Hello World')

 

相关文章:

  • 2021-11-21
  • 2022-01-13
  • 2021-10-07
  • 2021-06-25
  • 2022-12-23
  • 2022-01-06
  • 2021-10-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-04
相关资源
相似解决方案