dabeaz-course/practical-python

Chapter 2.2 Containers - Excercise 2.5: List of Dictionaries: Missing path

Closed this issue · 1 comments

Hi Dave,
I've just found this tiny bug in the example below. As mentioned on more than one occasion it is assumed that our working directory is ./Work/ therefore the code below will raise a FileNotFoundError because of the missing path.

Exercise 2.5: List of Dictionaries
Take the function you wrote in Exercise 2.4 and modify to represent each stock in the portfolio with a dictionary instead of a tuple. In this dictionary use the field names of "name", "shares", and "price" to represent the different columns in the input file.

Experiment with this new function in the same manner as you did in Exercise 2.4.

>>> portfolio = read_portfolio('portfolio.csv')

results in:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "report.py", line 24, in read_portfolio
    with open(filename, 'rt') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'portfolio.csv'

To fix this add the correct path to the file:

>> portfolio = read_portfolio('Data/portfolio.csv')

Fixed!