diff options
Diffstat (limited to 'Doc/faq/design.rst')
-rw-r--r-- | Doc/faq/design.rst | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Doc/faq/design.rst b/Doc/faq/design.rst index 68570b3..720b1e4 100644 --- a/Doc/faq/design.rst +++ b/Doc/faq/design.rst @@ -708,6 +708,15 @@ bindings are resolved at run-time in Python, and the second version only needs to perform the resolution once. +Why don't generators support the with statement? +------------------------------------------------ + +For technical reasons, a generator used directly as a context manager +would not work correctly. When, as is most common, a generator is used as +an iterator run to completion, no closing is needed. When it is, wrap +it as "contextlib.closing(generator)" in the 'with' statment. + + Why are colons required for the if/while/def/class statements? -------------------------------------------------------------- |