From 24d06f216921c3515de49ba988700f79d6be6e58 Mon Sep 17 00:00:00 2001 From: Mike Bloy Date: Fri, 27 Oct 2023 16:43:51 -0500 Subject: [PATCH] ex3.1 b --- stock.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/stock.py b/stock.py index 1fb01ca..3ed2ee0 100644 --- a/stock.py +++ b/stock.py @@ -1,3 +1,6 @@ +import csv + + class Stock: def __init__(self, name, shares, price): self.name = name @@ -11,3 +14,10 @@ class Stock: self.shares -= num if self.shares < 0: self.shares = 0 + + +def read_portfolio(filename): + with open(filename) as f: + rows = csv.reader(f) + _ = next(rows) + return [Stock(row[0], row[1], row[2]) for row in rows]