diff options
author | Georg Brandl <georg@python.org> | 2008-03-03 21:31:50 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-03-03 21:31:50 (GMT) |
commit | 8e67ef52dbb8434cc571b9ed3b6bfa6096e077da (patch) | |
tree | 151698273db3f1f9576ed069560a27ab5871157e /Doc/reference | |
parent | d2f7680b8fb53227e365e4ffef727c386b8a644c (diff) | |
download | cpython-8e67ef52dbb8434cc571b9ed3b6bfa6096e077da.zip cpython-8e67ef52dbb8434cc571b9ed3b6bfa6096e077da.tar.gz cpython-8e67ef52dbb8434cc571b9ed3b6bfa6096e077da.tar.bz2 |
Expand a bit on genexp scopes.
Diffstat (limited to 'Doc/reference')
-rw-r--r-- | Doc/reference/expressions.rst | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 23958ee..0653910 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -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 for each iteration. -Variables used in the generator expression are evaluated lazily when the -:meth:`next` method is called for generator object (in the same fashion as -normal generators). However, the leftmost :keyword:`for` clause is immediately -evaluated so that error produced by it can be seen before any other possible -error in the code that handles the generator expression. Subsequent -:keyword:`for` clauses cannot be evaluated immediately since they may depend on -the previous :keyword:`for` loop. For example: ``(x*y for x in range(10) for y -in bar(x))``. +Variables used in the generator expression are evaluated lazily in a separate +scope when the :meth:`next` method is called for the generator object (in the +same fashion as for normal generators). However, the :keyword:`in` expression +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 +:keyword:`for` and :keyword:`if` clauses cannot be evaluated immediately since +they may depend on the previous :keyword:`for` loop. For example: +``(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 :ref:`calls` for the detail. |