Practicum 5: More Objects

Objectives:

  • Apply your work with objects to past work

Files Modified: report.py, tableformat.py

In this project, you’re going to take everything you did in section 5 and apply it to your previous written report.py program. You task is simple:

  • Modify report.py to use the Stock class you implemented in the the stock.py file.

  • Modify report.py to produce output using the TableFormatter classes you implemented in tableformat.py.

  • Modify the code so that it allows the user to specify an output format (Text, CSV, HTML, etc.) on the command line. For example:

bash % python report.py --format=csv Data/portfolio.csv Data/prices.csv
Name,Shares,Price,Change
AA,100,39.91,7.71
IBM,50,106.11,15.01
CAT,150,78.58,-4.86
MSFT,200,30.47,-20.76
GE,95,37.38,-2.99
MSFT,50,30.47,-34.63
IBM,100,106.11,35.67
bash %
  • Modify the code in tableformat.py so that output can be redirected to a file of the user’s choosing (instead of just being printed to sys.stdout).

  • Modify report.py so that it optionally allows the output to be written to a file instead of standard out. For example:

bash % python report.py --format=csv -o output.csv Data/portfolio.csv Data/prices.csv
bash % cat output.csv
Name,Shares,Price,Change
AA,100,39.91,7.71
IBM,50,106.11,15.01
CAT,150,78.58,-4.86
MSFT,200,30.47,-20.76
GE,95,37.38,-2.99
MSFT,50,30.47,-34.63
IBM,100,106.11,35.67

This practicum will probably not involve a huge amount of coding, but you’ll need to tie together a lot of work from past exercises.

Links

[ Back | Next | Index ]