Python closure function losing outer variable access

前端 未结 3 1118
时光取名叫无心
时光取名叫无心 2021-02-19 07:36

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):
         


        
3条回答
  •  没有蜡笔的小新
    2021-02-19 08:02

    You assign param1 in the function, which makes param1 a local variable. However, it hasn't been assigned at the point you're printing it, so you get an error. Python doesn't fall back to looking for variables in outer scopes.

提交回复
热议问题