writable iterators?

MRAB python at mrabarnett.plus.com
Wed Jun 22 20:34:50 EDT 2011


On 23/06/2011 00:10, Neal Becker wrote:
> Steven D'Aprano wrote:
>
>> On Wed, 22 Jun 2011 15:28:23 -0400, Neal Becker wrote:
>>
>>> AFAICT, the python iterator concept only supports readable iterators,
>>> not write. Is this true?
>>>
>>> for example:
>>>
>>> for e in sequence:
>>>    do something that reads e
>>>    e = blah # will do nothing
>>>
>>> I believe this is not a limitation on the for loop, but a limitation on
>>> the python iterator concept.  Is this correct?
>>
>> Have you tried it? "e = blah" certainly does not "do nothing", regardless
>> of whether you are in a for loop or not. It binds the name e to the value
>> blah.
>>
>
> Yes, I understand that e = blah just rebinds e.  I did not mean this as an
> example of working code.  I meant to say, does Python have any idiom that allows
> iteration over a sequence such that the elements can be assigned?
>
[snip]
Python has references to objects, but not references to references.



More information about the Python-list mailing list