Mรณdulo 04 ยท Errors, Files & JSON โ Lecciรณn 2 de 3 ยท ~8 min
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.