A "with" statement is recommend when using open() to read files

Such as:

import csv

with open('example.csv') as f:
    example_data = list(csv.reader(f))

See here for more information. It’s not a huge issue in the early missions, but I think it’s good practice.

1 Like

Hey, Charlie. Thank you for this feedback.

We actually teach this in the data engineering path. I think we decided to leave this out in the Data Scientist path because we judged it an unimportant detail at that point in the learning journey.

There are actually good reasons (other than it being a best practice). You can read more about them in the Encodings and Representing Text in a Computer mission of the Programming Concepts with Python course in the Data Engineering path.

Sounds good, thanks for the reply! Yep, it helps with memory cleanup and ensuring the file is closed in the case of exceptions.

I’m thinking I should have started on the Data Scientist or Engineering path (currently Data Analyst) because I have this Python background already.

1 Like