A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2007-May/073113.html below:

[Python-Dev] generators and with

[Python-Dev] generators and with [Python-Dev] generators and withDuncan Booth duncan.booth at suttoncourtenay.org.uk
Sun May 13 18:47:17 CEST 2007
"tomer filiba" <tomerfiliba at gmail.com> wrote in
news:1d85506f0705130756j396a197bhf2f694d75ba06101 at mail.gmail.com: 

> why not add __enter__ and __exit__ to generator objects?
> it's really a trivial addition: __enter__ returns self, __exit__ calls
> close().
> it would be used to ensure close() is called when the generator is
> disposed, instead of doing that manually. typical usage would be:
> 
> with mygenerator() as g:
>     g.next()
>     bar = g.send("foo")
> 

You can already ensure that the close() method is called quite easily:

with contextlib.closing(mygenerator()) as g:
   g.next()
   bar = g.send("foo")

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4