Re: [Python-Dev] generators and with

2007-05-13 Thread Duncan Booth
"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, inste

Re: [Python-Dev] generators and with

2007-05-13 Thread dustin
On Sun, May 13, 2007 at 04:56:15PM +0200, tomer filiba wrote: >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

[Python-Dev] generators and with

2007-05-13 Thread tomer filiba
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: