Class attribute evaluation and generators

前端 未结 2 1243
猫巷女王i
猫巷女王i 2021-01-07 23:17

How exactly does Python evaluate class attributes? I\'ve stumbled across an interesting quirk (in Python 2.5.2) that I\'d like explained.

I have a class with some a

2条回答
  •  广开言路
    2021-01-07 23:45

    From PEP 289:

    After exploring many possibilities, a consensus emerged that binding issues were hard to understand and that users should be strongly encouraged to use generator expressions inside functions that consume their arguments immediately. For more complex applications, full generator definitions are always superior in terms of being obvious about scope, lifetime, and binding [6].

    [6] (1, 2) Patch discussion and alternative patches on Source Forge http://www.python.org/sf/872326

    It's how generator expressions are scoped as far as I can make out.

提交回复
热议问题