[Python-ideas] Fwd: should there be a difference between generators and iterators?
szport at gmail.com
Wed Sep 10 20:49:08 CEST 2008
---------- Forwarded message ----------
From: Zaur Shibzoukhov <szport at gmail.com>
Subject: Re: [Python-ideas] should there be a difference between generators
To: Bruce Frederiksen <dangyogi at gmail.com>
I think it should be as
types.GeneratorType.__enter__ = MethodType(lambda self: self,
types.GeneratorType.__exit__ = MethodType(lambda self: self.close(),
>So that the objects returned by his generator functions (functions
>have context manager capability?
2008/9/10 Bruce Frederiksen <dangyogi at gmail.com>:
> Zaur Shibzoukhov wrote:
>> Bruce Frederiksen wrote:
>>> Since there is no need to clean up after iterators in general, but only
>>> for generators specifically; and since the BDFL has nixed my point #5,
>>> it makes sense to only add the __enter__ and __exit__ to generators.
>>> (And, by extension, itertools).
>> It makes more sense to allow extending of builtin types in order to
>> support different protocols
>> (not only protocol for "with" statement)
> Do you mean the python programmer should do:
> import types
> types.GeneratorType.__enter__ = lambda self: self
> types.GeneratorType.__exit__ = lambda self: self.close()
> So that the objects returned by his generator functions (functions
> containing 'yield') have context manager capability?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas