Python doesn't remove the variables once a scope is closed (if there's such a thing as scope in Python, I'm not sure). I mean, once I finish a for variable in range(1, 100)
, the variable
is still there, with a value (99
in this case).
Now I usually indent a whole block when I use the with ... as
statement. But should I close the file and end the indentation as soon as I'm done with it? I mean, should I write:
with open('somefile', 'r') as f:
newvar = f.read()
newvar.replace('a', 'b') # and etc
Instead of:
with open('somefile', 'r') as f:
newvar = f.read()
newvar.replace('a', 'b') # and etc