"tomer filiba" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]:
> 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") _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com