from dataclasses import dataclass, field import pickle from typing import List @dataclass class Transaction: person: str value: int description: str @dataclass class Project: acronym: str title: str description: str amount: int history: List[Transaction] = field(default_factory=list) if __name__ == "__main__": history = [Transaction(f"person {i}", i, f"description {i}") for i in range(10)] project1 = Project("acronym", "title", "description", 500, history) with open("file", "wb+") as file1: pickle.dump(project1, file1) with open("file", "rb") as file2: project2 = pickle.load(file2) print(project2)