What is the most pythonic way to change first byte of file to its inversion copy?
Now, I use this code:
with open(file_path, 'r+b') as f:
b = bytearray(f.read(1))
b = ~b & 255
Here's an alternative that uses a memory-mapped file:
import mmap with open(file_path, 'r+b') as f, mmap.mmap(f.fileno(), 1) as mm: mm ^= 255