with open('somefile.bin', 'rb') as f: data = f.read()
with open('somefile.bin', 'wb') as f: f.write(b'Hello World')