You need to open the file in binary write mode (wb
).
with open('file2.bin', 'wb') as f:
f.write(myArr)
Also, the way you are reading from the input file is pretty inefficient. f.read()
allows you to read more than one byte at a time:
with open('file1.bin', 'rb') as f:
myArr = bytearray(f.read(32678))
Will do exactly what you want.