Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8245
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Mel <mwilson@the-wire.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: writable iterators? |
| Followup-To | comp.lang.python |
| Date | Wed, 22 Jun 2011 17:59:47 -0400 |
| Organization | Aioe.org NNTP Server |
| Lines | 54 |
| Message-ID | <ittokg$r6n$1@speranza.aioe.org> (permalink) |
| References | <mailman.296.1308770918.1164.python-list@python.org> <4e026497$0$29975$c3e8da3$5496439d@news.astraweb.com> |
| Reply-To | mwilson@the-wire.com |
| NNTP-Posting-Host | K0G0P3f5CpSv7FWGvAjxIA.user.speranza.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | KNode/4.4.8 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:8245 |
Followups directed to: comp.lang.python
Show key headers only | View raw
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.
>
>>>> seq = [1, 2]
>>>> for e in seq:
> ... print(e)
> ... e = 42
> ... print(e)
> ...
> 1
> 42
> 2
> 42
>
>
> 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.
Mel.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
writable iterators? Neal Becker <ndbecker2@gmail.com> - 2011-06-22 15:28 -0400
Re: writable iterators? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-22 21:54 +0000
Re: writable iterators? Mel <mwilson@the-wire.com> - 2011-06-22 17:59 -0400
Re: writable iterators? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-06-23 01:30 +0200
Re: writable iterators? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-23 11:53 +1000
Re: writable iterators? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-06-23 12:23 +0200
Re: writable iterators? Neal Becker <ndbecker2@gmail.com> - 2011-06-22 19:10 -0400
Re: writable iterators? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-23 11:50 +1000
Re: writable iterators? MRAB <python@mrabarnett.plus.com> - 2011-06-23 01:34 +0100
Re: writable iterators? Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-23 09:02 -0600
Re: writable iterators? Neal Becker <ndbecker2@gmail.com> - 2011-06-23 12:06 -0400
Re: writable iterators? Chris Torek <nospam@torek.net> - 2011-06-23 18:26 +0000
Re: writable iterators? Chris Torek <nospam@torek.net> - 2011-06-23 22:17 +0000
Re: writable iterators? Neal Becker <ndbecker2@gmail.com> - 2011-06-23 21:10 -0400
csiph-web