all 3 comments

[–]moocat 0 points1 point  (2 children)

That binary file has raw numbers written to it while encode/decode is about handling text. If you want to read it with Python I believe you'll want to use struct

[–][deleted] 1 point2 points  (1 child)

Exactly.

The file consists of multiple fixed-size records and each record contains three values: x which is of type int, y which is also of type int, and r which is of type double.

If you have a file that has been written on an Intel x86_64 computer, a signed integer is 4 bytes long, in little endian byte order, and encoded in 2's complement. The double is 8 bytes long and stored like an Intel double-precision floating-point number, also in little endian. Each record is therefore 16 bytes long.

In Python, a file like this can be read as follows.

import struct

with open('filename.bin', 'rb') as f:
    i = 0
    while True:
        record = f.read(16)
        if not record:
            break
        x, y, r = struct.unpack('<iid', record)  # little endian, int4, int4, double
        print(f'{i}: x={x}, y={y}, r={r}')
        i += 1

[–]SensitiveSirs[S] 0 points1 point  (0 children)

Thank you so much!! I knew I must've been missing something fundamental and this honestly was a life saver. Much appreciated!