如何从嵌套方法访问外部容器变量

2024-04-16 07:39:30 发布

您现在位置:Python中文网/ 问答频道 /正文

考虑:

 def outerMethod(outerParam):

   outerLocal = "foo"

   def innerMethod(innerParam):
      # locals() will not work here
      print("%(outerParam)s %(outerLocal) %(innerParam)" %locals())

访问外部参数和外部本地的正确方法是什么

更新问题与嵌套方法有关,因此问题已更新


Tags: 方法参数herefoodefnotwillwork