从类定义中的列表理解中访问类变量
class Foo: x = 5 y = [x for i in range(1)]
NameError: global name 'x' is not defined
Foo.x
from collections import namedtupleclass StateDatabase: State = namedtuple('State', ['name', 'capital']) db = [State(*args) for args in [ ['Alabama', 'Montgomery'], ['Alaska', 'Juneau'], # ... ]]
apply()
料青山看我应如是
牧羊人nacy
相关分类