静态变量:未在其他构造函数中定义

时间:2018-02-13 09:12:56

标签: python python-3.x python-3.5 python-internals

我无法访问类的静态成员。我的用例最简单的例子是:

class A:
    _tmpl = '<{}>'
    print(_tmpl)
    VAR = tuple(_tmpl.format(var) for var in ('a', 'b'))

这将从<{}>语句中打印print;但是tuple的行引发了异常:

NameError: name '_tmpl' is not defined

这里发生了什么?我该如何修复它(A._tmpl也无效......)。

0 个答案:

没有答案
相关问题