Exporting arbitrary fields in list of dataclass objects to a dict?
Exporting arbitrary fields in list of dataclass objects to a dict? Question: Consider this example: from dataclasses import dataclass, asdict, astuple @dataclass class Player: id: int name: str color: str players = [ Player(123, "Alice", "green"), Player(456, "Bob", "red"), Player(789, "Gemma", "blue"), ] print("players:", players) print("players[0] as dict:", asdict( players[0] ) ) The printout I …