writable iterators?

Benjamin Kaplan benjamin.kaplan at case.edu
Wed Jun 22 16:52:02 EDT 2011


On Jun 22, 2011 12:31 PM, "Neal Becker" <ndbecker2 at gmail.com> 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?

consider the following code

x = [1,2,3]
y = x[0]
y = 5

Would you expect x to be [5,2,3] now? Assignment in python assigns a name to
an object. It doesn't change the value of a variable.

If you have a generator, you can use send() to put data in you need the
actual generator itself to do that.

>
> --
> http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110622/7a322529/attachment-0001.html>


More information about the Python-list mailing list