MCPcopy Index your code
hub / github.com/dabeaz-course/practical-python / read_portfolio

Function read_portfolio

Solutions/4_10/report.py:7–18  ·  view source on GitHub ↗

Read a stock portfolio file into a list of dictionaries with keys name, shares, and price.

(filename)

Source from the content-addressed store, hash-verified

5import tableformat
6
7def read_portfolio(filename):
8 '''
9 Read a stock portfolio file into a list of dictionaries with keys
10 name, shares, and price.
11 '''
12 with open(filename) as lines:
13 portdicts = fileparse.parse_csv(lines,
14 select=['name','shares','price'],
15 types=[str,int,float])
16
17 portfolio = [ Stock(d['name'], d['shares'], d['price']) for d in portdicts ]
18 return portfolio
19
20def read_prices(filename):
21 '''

Callers 1

portfolio_reportFunction · 0.70

Calls 1

StockClass · 0.90

Tested by

no test coverage detected