Python 读写字节数据(转)

转自: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')

 

posted @ 2022-01-09 13:32  Lucky小黄人^_^  阅读(279)  评论(0编辑  收藏  举报