[issue13814] Generators as context managers.

2012-01-20 Thread Terry J. Reedy
Terry J. Reedy added the comment: Calling g.close() is pointless for a generator used in normal pull mode and run to completion, as in the example. The generator is already 'closed', so g.close() does not do anything useful. See http://docs.python.org/py3k/reference/expressions.html#yield-expr

[issue13814] Generators as context managers.

2012-01-20 Thread Antoine Pitrou
Changes by Antoine Pitrou : -- nosy: +ncoghlan versions: +Python 3.3 -Python 2.7, Python 3.4 ___ Python tracker ___ ___ Python-bugs-li

[issue13814] Generators as context managers.

2012-01-18 Thread Ezio Melotti
Ezio Melotti added the comment: If you want to call .close() automatically on something you can use contextlib.closing(): http://docs.python.org/library/contextlib.html#contextlib.closing -- nosy: +ezio.melotti ___ Python tracker

[issue13814] Generators as context managers.

2012-01-18 Thread Arkadiusz Wahlig
New submission from Arkadiusz Wahlig : Generators should support the with statement with __exit__ calling self.close(). with genfunc() as g: for item in g: print(item) -- messages: 151530 nosy: yak priority: normal severity: normal status: open title: Generators as context m