Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8242 > unrolled thread

Re: writable iterators?

Started byEthan Furman <ethan@stoneleaf.us>
First post2011-06-22 13:04 -0700
Last post2011-06-22 13:04 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: writable iterators? Ethan Furman <ethan@stoneleaf.us> - 2011-06-22 13:04 -0700

#8242 — Re: writable iterators?

FromEthan Furman <ethan@stoneleaf.us>
Date2011-06-22 13:04 -0700
SubjectRe: writable iterators?
Message-ID<mailman.297.1308772187.1164.python-list@python.org>
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~

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web