I want to learn Python, but currently I am stuck. My goal is to read in a file and then compare 8 bytes of that file with some other 8 bytes.I read the whole file in memory and now I want to iterate over the object and do the comparison check in 8 byte chunks as an exercise.
This is my code:
with open("read.file", 'rb') as f:
read_file = f.read()
i = 0
while (i <= len(read_file)):
chunk = read_file[i:i+8]
print(sys.getsizeof(chunk))
i += 8
I know I could just read 8 bytes in the first loop and do the comparison there, but I am interested if there is a solution to this.
when running the code, sys.getsizeof(chunk)
returns 41 bytes. Has anyone an idea what I might have overlooked?