Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8242
| Date | 2011-06-22 13:04 -0700 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | Re: writable iterators? |
| References | <ittfon$nku$1@dough.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.297.1308772187.1164.python-list@python.org> (permalink) |
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?
No. e = blah will rebind the indentifier 'e' with 'blah' whatever that
is. That is how python works.
Now, if e is mutable, say a list, you can do
e.append(blah)
and, since the name 'e' is not being rebound, you would see the change
in 'sequence'.
~Ethan~
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: writable iterators? Ethan Furman <ethan@stoneleaf.us> - 2011-06-22 13:04 -0700
csiph-web