I saw this snippet in a code that I am working on. And I feel that accessing the outer function variable directly in the inner function brings some undesirable magic. For e.g. when I read the function, I assume that the variables I am manipulating in that function is gotten from the parameters
def outer_function(): filename = os.path.abspath("some.config") def inner_function(state): with open(filename, "w+") as f: f.write(state) f.flush() os.fsync(f.fileno()) os.rename(filename + ".ext" , filename)
- What are the drawbacks of inner_function accessing the variable
filenamedirectly from it's immediate outer scope?
- Are there any stylistic drawbacks/concerns in this snippet of code?