0

I am new to python. I am writing a code to read a mask file. The code is below. It runs fine. But when I remove the print line at the end it give me the error 'unpack requires a buffer of 1 bytes'. I don't want to print the data. Any help will be appreciated.

Thank you

filehandle= open(img_path+"/"+filename[0],'rb')
byte = filehandle.read(1)
mask=np.zeros(192*132)
L=0;
while byte:
    byte = filehandle.read(1)
    mask[L] = struct.unpack('<B', byte)[0]     
    print(mask[L])
    L=L+1
Progman
  • 16,827
  • 6
  • 33
  • 48
  • Ideally you would share detailed error information, such as a stack trace, but in this case it seems that you would have a problem when you reach the end of the file, because you unpack immediately after reading. I think you intend to unpack first. – brainchild May 17 '20 at 06:44
  • To help in the future, please consider reading the [guidelines for writing questions](https://stackoverflow.com/help/how-to-ask), particularly about [writing an example](https://stackoverflow.com/help/minimal-reproducible-example). – brainchild May 17 '20 at 06:55

0 Answers0