4 ms·
> the file will be reliably closed at the end of the statement. The only guarantee CPython makes is that it may eventually close the file once all references a
by nicolaslem 4y ago
> the file will be reliably closed at the end of the statement.
The only guarantee CPython makes is that it may eventually close the file once all references are gone. The fact that it does it immediately and reliably in this specific case is an implementation detail and should not be relied upon.
Use context managers when things need to be closed and save yourself trouble down the line.