Python closure function losing outer variable access
问题 I just learned python @ decorator, it's cool, but soon I found my modified code coming out weird problems. def with_wrapper(param1): def dummy_wrapper(fn): print param1 param1 = 'new' fn(param1) return dummy_wrapper def dummy(): @with_wrapper('param1') def implementation(param2): print param2 dummy() I debug it, it throws out exception at print param1 UnboundLocalError: local variable 'param1' referenced before assignment If I remove param1 = 'new' this line, without any modify operation