How to modify the local namespace in python

前端 未结 7 524
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-01 19:39

How can I modify the local namespace of a function in python? I know that locals() returns the local namespace of the function when called inside it, but I want to do somet

7条回答
  •  庸人自扰
    2020-12-01 20:34

    Why don't you just add an argument to f() and pass a reference to g()?

    def g():
        pass
    
    def f(func):
        func()
    
    f(g)
    

提交回复
热议问题