I'm trying to merge two binary files to third binary file in Python. My code:
input1 = input2 = ""
input1 = open('input1.bin').read()
input2 = open('input2.bin').read()
input1 += input2
with open('Output.bin', 'w') as fp:
fp.write(input1)
This code is not giving me any error but this is not generating the expected output.
Like, if I wrote the batch command to merge the files:
copy /b input1.bin+input2.bin Output.bin
This command is generating the Output.bin
of size 150KB whereas the earlier python command is giving me Output file size as 151KB.
I have tried this as well:
with open('Output.bin', 'wb') as fp:
fp.write(input1)
i.e. to write using binary mode, but this gave me error as:
TypeError: a bytes-like object is required, not 'str'
What could be the correct process for this?
Referred this for earlier error: TypeError: a bytes-like object is required, not 'str' when writing to a file in Python3
This solution is not working.
Using Python 3.7