The with Statement for Resources in Python


Automatically manage resources with the with statement.

Source Code

# Automatically close the file when done
with open("example.txt", "r") as f:
    content = f.read()
    print(content)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments