Strange python closure variable access
Strange python closure variable access Question: While trying to implement a decorator with a closure I ran into a somewhat strange behavior, where a variable can be read, but if try to assign it later, it becomes undefined even before the assignment. def run_once(fn): to_run = True def decorated(*args, **kwargs): if to_run: print(to_run) #this access …