V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  xcai007  ›  全部回复第 2 页 / 共 2 页
回复总数  21
1  2  
2020-10-29 18:05:02 +08:00
回复了 hhvv23911k 创建的主题 Python 请教如何使用 Python 直接对二进制文件进行修改
用 mmap

import mmap
with open('file', 'rb) as f:
with mmap.mmap(f.fileno(), length=0, access=mmap.ACCESS_READ) as contents:
start = contents.find('test')
print(contents[:start]+'mytest'+contents[start+len('test'):]
1  2  
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   2742 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 10ms · UTC 12:40 · PVG 20:40 · LAX 04:40 · JFK 07:40
♥ Do have faith in what you're doing.