ex3.1 b
This commit is contained in:
parent
80976ba906
commit
24d06f2169
10
stock.py
10
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]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user