fork download
  1. import mmap
  2.  
  3. new = '555'
  4. pattern = b'substr1:\x00\x00'
  5.  
  6. with open('test.bin', 'r+b') as f:
  7. mm = mmap.mmap(f.fileno(), 0)
  8.  
  9. pos = mm.find(pattern)
  10. if pos:
  11. mm.seek(pos + len(pattern))
  12. mm.write(new.encode())
  13.  
  14. mm.close()
Runtime error #stdin #stdout #stderr 0.15s 23484KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 6, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'test.bin'