Files & context managers

Opening a file

open(path) gives you a file object you can read from. But a file is a resource, like a network socket โ€” it must be closed when you're done, or you leak file handles.

Swift makes you remember cleanup with defer. Python has a construct that makes closing automatic: with.