Chapters
Python114 chapters

ReferenceKeywords

with

Runs setup and guaranteed cleanup around a block, most often for files.

Signature

with expression as name:

Returns

Nothing.

Example

Python
with open("notes.txt", "w", encoding="utf-8") as f:
    f.write("one")

print(f.closed)

Output

True

See also