mercredi 17 avril 2019

The While statement fails the compare when using Bytes It seems it only takes int

I want to compare bytes in a video file.ser that has 8 bit data. I need to find the first non zero byte at the beginning of the frame. I use red = mm.read(1) to receive a byte direct from the file on disk because the files are huge. I seems that While and if compare int data and fail to deliver the correct comparison when attempting to compare int(0) == b´\00 and Byte(0)==b´\00

"If" displayed the same effect and my attempt to redefine the variables as int have exceeded my knowledge.

mm = mmap.mmap(f.fileno(),0) #0=read the whole file
red = 0 #This value is int
print ("Red ",red) #Confirm int

while  red == 0:      # This works First time

    red = mm.read(1) # Now red is Byte 
    print ("Red = ",red, "Position  ", mm.tell(),"\r" ) #red is b´\x00

else:
    print ("Red = ",red, "Position exit ", mm.tell() ) # exit because red is Byte

The first compare can only be True if both halves of the comparison are int. All other cases exit the while after one loop

Aucun commentaire:

Enregistrer un commentaire