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

Function read_portfolio

Solutions/6_15/report.py:8–19  ·  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

6from portfolio import Portfolio
7
8def read_portfolio(filename):
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
18 portfolio = [ Stock(d['name'], d['shares'], d['price']) for d in portdicts ]
19 return Portfolio(portfolio)
20
21def read_prices(filename):
22 '''

Callers 1

portfolio_reportFunction · 0.70

Calls 2

StockClass · 0.90
PortfolioClass · 0.90

Tested by

no test coverage detected