Read a stock portfolio file into a list of dictionaries with keys name, shares, and price.
(filename, **opts)
| 6 | from portfolio import Portfolio |
| 7 | |
| 8 | def 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 | |
| 22 | def read_prices(filename, **opts): |
| 23 | ''' |
no test coverage detected