I have two binary data files and I want to replace the contents of part of the second binary data file This is the sample code I have so far
Binary_file1 = open("File1.yuv","rb")
Binary_file2 = open("File2.yuv","rb")
data1 = Binary_file1.read()
data2 = Binary_file2.read()
bytes = iter(data1)
for i in range(4, 10):
data2[i] = next(bytes)
It fails at the part where I equate the data2[i] with next(bytes) and gives me an error saying that “'str' object does not support item assignment” The part I dont understand is that how is this a string object and how can I resolve this error ,Any help would be appreciated . PLease note the Binary files here are huge and I would like to avoid creating duplicate files as I alwyas will run into Memory Issues
You opened file and read it. So, You have string in
data2
. Strings do not support item assignment.Instead, You could do: