python 字节读写

  • 2019 年 10 月 10 日
  • 筆記

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')