Assigning to a target
suggest changeThe as clause binds whatever __enter__ returns. It is not necessarily the context manager itself.
File objects return themselves, which makes it possible to both open the file object and use it as a context manager in one expression:
with open(filename) as open_file:
file_contents = open_file.read()
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents