Context Managers

A way to manage resources that need to be properly opened and closed.

with open('file.txt') as f:
    # file is automatically closed when exiting this block

See also: Python