If I'm going to pass an open(filename)
object directly as argument to another method, say json.load()
, in this way:
data = json.load(open("filename.json"))
can I be sure that the open stream is garbage-collected, thus closed, as soon as json.load()
finishes its execution, or I'm going to face corruption issues very soon?
I know the best practice would be with open(filename) as f:
syntax, but what if I insisted for a one-liner solution?