What is the difference between:
data = open(filename).read()
And:
with open(filename) as handle:
data = handle.read()
?
I would like to know:
- Will the
.close()
method be called in both cases? - At roughly the same time? I have the impression in the first case the
.close()
method will only be called when garbage collection kicks in.
I like the first version because it's a single line.