Read a stock portfolio file into a list of dictionaries with keys name, shares, and price.
(filename)
| 5 | import tableformat |
| 6 | |
| 7 | def 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 | |
| 20 | def read_prices(filename): |
| 21 | ''' |
no test coverage detected