Expand a bit on genexp scopes.
This commit is contained in:
parent
d2f7680b8f
commit
8e67ef52db
|
@ -230,14 +230,15 @@ generator are those that would be produced by considering each of the
|
||||||
evaluating the expression to yield a value that is reached the innermost block
|
evaluating the expression to yield a value that is reached the innermost block
|
||||||
for each iteration.
|
for each iteration.
|
||||||
|
|
||||||
Variables used in the generator expression are evaluated lazily when the
|
Variables used in the generator expression are evaluated lazily in a separate
|
||||||
:meth:`next` method is called for generator object (in the same fashion as
|
scope when the :meth:`next` method is called for the generator object (in the
|
||||||
normal generators). However, the leftmost :keyword:`for` clause is immediately
|
same fashion as for normal generators). However, the :keyword:`in` expression
|
||||||
evaluated so that error produced by it can be seen before any other possible
|
of the leftmost :keyword:`for` clause is immediately evaluated in the current
|
||||||
|
scope so that an error produced by it can be seen before any other possible
|
||||||
error in the code that handles the generator expression. Subsequent
|
error in the code that handles the generator expression. Subsequent
|
||||||
:keyword:`for` clauses cannot be evaluated immediately since they may depend on
|
:keyword:`for` and :keyword:`if` clauses cannot be evaluated immediately since
|
||||||
the previous :keyword:`for` loop. For example: ``(x*y for x in range(10) for y
|
they may depend on the previous :keyword:`for` loop. For example:
|
||||||
in bar(x))``.
|
``(x*y for x in range(10) for y in bar(x))``.
|
||||||
|
|
||||||
The parentheses can be omitted on calls with only one argument. See section
|
The parentheses can be omitted on calls with only one argument. See section
|
||||||
:ref:`calls` for the detail.
|
:ref:`calls` for the detail.
|
||||||
|
|
Loading…
Reference in New Issue