I have a very large binary file called file1.bin and I want to create a file, file2.bin, that holds only the first 32kb of file1.bin.
So I'm reading file1 as follows:
myArr = bytearray()
with open(r"C:\Users\User\file1.bin", "rb") as f:
byte = f.read(1)
for i in range(32,678):
myArr.extend(byte)
byte = f.read(1)
My question is: How do I proceed from here to create the file2 binary file out of myArr?
I tried
with open(r"C:\Users\User\file2.bin", "w") as f:
f.write(myArr)
but this results in:
f.write(myArr)
TypeError: must be string or pinned buffer, not bytearray
shutilmodule? Last but not least, do use theironpythontag as it might be relevant.'rb', why did you open the file to write to in text mode instead?'wb'would solve the exception you have in one go.range(32,768)is[32, 33, 34, 35, ... 766, 767]. You really don't want that comma.