【发布时间】:2020-08-31 17:12:31
【问题描述】:
我尝试使用此代码删除大文件的每 5 个字节,但它不起作用:
from io import BytesIO
f = open("data.bin", 'rb')
chunk = f.read(5)
while chunk:
# Truncate the chunk.
BytesIO(chunk).truncate(5 - 1)
chunk = f.read(5)
f.close()
怎么了?
【问题讨论】:
-
您的文件以只读方式打开。为什么您希望文件更改?