I wish you could compile scons with pypi.
contents = open(file).read()
where they should be doing
with open(file) as fid: contents = fid.read()
Technically the guarantee in CPython is "soft" so it can be a problem, just rarely is: if the file gets referenced from an object accessible from a cycle the file won't be released (and closed) until the cycle-breaking GC is triggered.
f = open('foo.txt')
contents = f.read()
f.close()
But I'd prefer this way: with open('foo.txt') as f:
contents = f.read()
Context managers can of course be used for all kinds of things. For more information, see https://docs.python.org/2/library/contextlib.html f = open('foo.txt')
try:
contents = f.read()
finally:
f.close()
So yes, extra reason to prefer the context manager.