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

Function read_portfolio

Solutions/7_4/report.py:8–20  ·  view source on GitHub ↗

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

(filename, **opts)

Source from the content-addressed store, hash-verified

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

Callers 1

portfolio_reportFunction · 0.70

Calls 2

StockClass · 0.90
PortfolioClass · 0.90

Tested by

no test coverage detected