A block is a piece of Python program text that is executed as a unit. The following are blocks: a module, a function body, and a class definition.
A scope defines the visibility of a name within a block.
The scope of names defined in a class block is limited to the class block; it does not extend to the code blocks of methods – this includes generator expressions since they are implemented using a function scope.
你需要使用
而不是
^{pr2}$在这种情况下。在
编辑:
由于scope resolution in Python规则,无法访问内部类中的
res_name
:关于Python范围解析,一个容易记住的规则是LEGB规则:
L.局部变量,即函数内指定的名称。在
封闭函数局部变量。在
G.全局
B.内置。在
当Django/tastype使用元类构造类时,
class Meta
被Django/tastype用作配置选项。我不知道为什么要从Meta
内部访问Meta
外部的变量,而不是仅仅在Meta
内部定义它。在相关问题 更多 >
编程相关推荐