Mở file nhị phân binary read/write, chỉ định 'w+b' (w=write, b=binary).
f = open('my_file.mp3', 'w+b')
file_content = f.read()
f.write(b'Hello')
f.close()
Mở my_file.mp3 binary read/write, lưu content vào biến, ghi đè "Hello" dạng binary. Cũng dùng r+b không truncate file.