0

I am new to binary files and trying to figure out how to read and manipulate them. I have the following code:

bfile = open('square.bmp', 'wb')

b = bytearray(bfile.read(bn))

while len(b) > 0:
    b = bytearray(bfile.read(bn))
    print(b)

bfile.close()

However, running this code is throwing errors and I do not know what I can replace the "bn" with or declare it as to run read the entire file.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Web Hopeful
  • 741
  • 2
  • 6
  • 11

1 Answers1

0
with open("square.bmp", "rb") as f:
   b = f.read(1)
   while b != b"":
      b = f.read(1)
lennon310
  • 12,503
  • 11
  • 43
  • 61