hi. i have a really basic question (really new to python). how do i read an entire binary file? from https://www.devdungeon.com/content/working-binary-data-python ,
data = binary_file.read() is to read the whole file at once. so i have a .dng file to test, which is 16.2mb, and i did:
with open("portrait1.dng", "rb") as binary_file: #Read the whole file at once data = binary_file.read() #Return the hexadecimal representation of the binary data, byte instance hexa = binascii.hexlify(data) with open("readprotrait1.raw", "wb") as write_file: write_file.write(hexa)
im using a hex editor to see if the data from .dng gets copied to the .raw file but only a portion of it gets copied. same result goes when i use a
while loop like :
while True: data = binary_file.read() if not data: break #return hex rep and write
if i put a size(1024) in the
.read(), only the last few lines of the data is written. so does it actually read the whole file and at the "write" part is where it gets complicated(doesn't write complete)? or am i missing something?