MCPcopy Create free account
hub / github.com/dabeaz-course/python-mastery / read_portfolio

Function read_portfolio

Solutions/3_2/stock.py:16–28  ·  view source on GitHub ↗

Read a CSV file of stock data into a list of Stocks

(filename)

Source from the content-addressed store, hash-verified

14
15
16def read_portfolio(filename):
17 '''
18 Read a CSV file of stock data into a list of Stocks
19 '''
20 import csv
21 portfolio = []
22 with open(filename) as f:
23 rows = csv.reader(f)
24 headers = next(rows)
25 for row in rows:
26 record = Stock(row[0], int(row[1]), float(row[2]))
27 portfolio.append(record)
28 return portfolio
29
30if __name__ == '__main__':
31 import tableformat

Callers 1

stock.pyFile · 0.70

Calls 2

appendMethod · 0.80
StockClass · 0.70

Tested by

no test coverage detected