Open
Description
Regarding the anti-pattern of not using with to open files, if you are reading the entire contents of the file in one shot as in the examples, you can use read_text
from pathlib
which opens and closes the file for you internally. So it isn't always an anti-pattern to not use a context manager for reading text/bytes, in fact I would argue that
with open("file.txt", "r") as f:
content = f.read()
is an anti-pattern for
content = Path("file.txt").read_text()
Metadata
Metadata
Assignees
Labels
No labels