Python nonlocal statement in a class definition

前端 未结 2 1587
走了就别回头了
走了就别回头了 2021-01-04 09:47

I\'m trying to perform some analysis of scope in Python 3 source code and I\'m stuck with how the nonlocal statement statement works inside a class definition.

As I

2条回答
  •  情书的邮戳
    2021-01-04 10:27

    Python handles class and function definitions rather differently. For example, your A.v is not a variable of A but rather an attribute of it. The namespace created by a class is not, therefore, a scope. I am not surprised that nonlocal does not work as you're trying to use it.

提交回复
热议问题