Consider the following:

with open(path, mode) as f:
    return [line for line in f if condition]

Will the file be closed properly, or does using return somehow bypass the context manager?

4 Answers
4

Leave a Reply

Your email address will not be published. Required fields are marked *