0

I have a binary file which is specified as "the file contains four fields. Each field is preceded by a 4-byte integer field that specifies its length."

What are the modules, that I need to take a look at in order to be able to read the four segments individually? I tried to open the file in binary mode and read the first 4 elements to get the size of the first field like so:

with open('file', 'rb') as in_file:
    lengthFirstField = in_file.read()[0:4]
    print(lengthFirstField)

But I guess that's wrong because I get four \x00 values which equals 0?

What is the proper way to do something like this?

Jabb
  • 3,414
  • 8
  • 35
  • 58

0 Answers0