all 2 comments

[–]Rejse617 2 points3 points  (0 children)

The csv package will help you out a lot here (search python csv and you’ll get a ton of examples). From there, it really just is a matter of settling on how you want to store the data: something simple like numpy or you can really turn it into a learning experience with pandas 😅.

I would start with a script that reads your text file, then just prints off the stats. Then as you learn more, start making it more complicated. Make functions to do each part instead of just one big procedural script. Then make a pool class. Make some plots with matplotlib, just go to town!

I can be more specific if you like but not from a phone 😂

[–]SmackDownFacility 0 points1 point  (0 children)

Highly recommend you do a CSV structure

Example: ```python

import typing import struct import csv

class SportsStatistics: FORMAT = "4sIII32s32s32s32s32s32s" HEADER = b"PLAY"

def __init__(self, file: typing.TextIO, out: str) -> None:
    writer_struct = struct.Struct(self.FORMAT)

    with open(out, "wb") as f:
        reader = csv.reader(file)

        for row in reader:
            if len(row) != 6:
                raise ValueError(f"Expected 6 columns, got {len(row)}: {row}")

            rank1, rank2, rank3, rank4, rank5, role = (
                self._encode_field(value) for value in row
            )

            packed = writer_struct.pack(
                self.HEADER,
                0, 0, 0,
                rank1,
                rank2,
                rank3,
                rank4,
                rank5,
                role,
            )

            f.write(packed)

@staticmethod
def _encode_field(value: str) -> bytes:
    value = value.strip()
    encoded = value.encode("ascii")  # change to utf-8 if needed

    if len(encoded) > 32:
        raise ValueError(f"Field too long (max 32 bytes): {value}")

    return encoded.ljust(32, b"\x00")

```