ca4006-ca2/classes.py
Malachy Byrne 41adade9fc
Added withdrawal capabilities.
TODO: improve logging, have researchers make use of withdrawal
2023-04-13 04:28:10 +01:00

30 lines
660 B
Python

from dataclasses import dataclass, field
import pickle
from typing import List
@dataclass
class Transaction:
person: str
value: int
@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)