writable iterators?
Thomas 'PointedEars' Lahn
PointedEars at web.de
Thu Jun 23 06:23:35 EDT 2011
[Sorry for over-quoting, I am not sure how to trim this properly]
Steven D'Aprano wrote:
> On Thu, 23 Jun 2011 09:30 am Thomas 'PointedEars' Lahn wrote:
>> Mel wrote:
>>> Steven D'Aprano wrote:
>>>> I *guess* that what you mean by "writable iterators" is that rebinding
>>>> e should change seq in place, i.e. you would expect that seq should now
>>>> equal [42, 42]. Is that what you mean? It's not clear.
>>>>
>>>> Fortunately, that's not how it works, and far from being a
>>>> "limitation", it would be *disastrous* if iterables worked that way. I
>>>> can't imagine how many bugs would occur from people reassigning to the
>>>> loop variable, forgetting that it had a side-effect of also reassigning
>>>> to the iterable. Fortunately, Python is not that badly designed.
>>>
>>> And for an iterator like
>>>
>>> def things():
>>> yield 1
>>> yield 11
>>> yield 4
>>> yield 9
>>>
>>> I don't know what it could even mean.
>>
>> <http://docs.python.org/reference/simple_stmts.html#the-yield-statement>
>>
>> You could have tried to debug.
>
> I think you have missed the point of Mel's comment. He knows what the
> yield statement does. He doesn't know what it would mean to "write to" an
> iterator like things().
>
> Neither do I.
AIUI the OP is referring to write accesses to the iteration variable
(for want of a better term), not being aware what iterators are.
--
PointedEars
Bitte keine Kopien per E-Mail. / Please do not Cc: me.
More information about the Python-list
mailing list