Re: writable iterators?

2011-06-23 Thread Thomas 'PointedEars' Lahn
[Sorry for over-quoting, I am not sure how to trim this properly] Steven D'Aprano wrote: On Thu, 23 Jun 2011 09:30 am Thomas 'PointedEars' Lahn wrote: Mel wrote: Steven D'Aprano wrote: I *guess* that what you mean by writable iterators is that rebinding e should change seq in place, i.e

Re: writable iterators?

2011-06-23 Thread Ian Kelly
On Wed, Jun 22, 2011 at 3:54 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: 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

Re: writable iterators?

2011-06-23 Thread Neal Becker
Ian Kelly wrote: On Wed, Jun 22, 2011 at 3:54 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: 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

Re: writable iterators?

2011-06-23 Thread Chris Torek
(I apologize for the length of this article -- if I had more time, I could write something shorter...) In article mailman.296.1308770918.1164.python-l...@python.org Neal Becker ndbeck...@gmail.com wrote: AFAICT, the python iterator concept only supports readable iterators, not write. Is this

Re: writable iterators?

2011-06-23 Thread Chris Torek
In article iu00fs1...@news3.newsguy.com I wrote, in part: Another possible syntax: for item in container with key: which translates roughly to bind both key and item to the value for lists, but bind key to the key and value for the value for dictionary-ish items. Then ... the OP would

Re: writable iterators?

2011-06-23 Thread Neal Becker
Chris Torek wrote: In article iu00fs1...@news3.newsguy.com I wrote, in part: Another possible syntax: for item in container with key: which translates roughly to bind both key and item to the value for lists, but bind key to the key and value for the value for dictionary-ish items. Then

Re: writable iterators?

2011-06-23 Thread Dan Stromberg
On Wed, Jun 22, 2011 at 12:28 PM, Neal Becker ndbeck...@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

writable iterators?

2011-06-22 Thread Neal Becker
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

Re: writable iterators?

2011-06-22 Thread Ethan Furman
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

Re: writable iterators?

2011-06-22 Thread Benjamin Kaplan
On Jun 22, 2011 12:31 PM, Neal Becker ndbeck...@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

Re: writable iterators?

2011-06-22 Thread Steven D'Aprano
... 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

Re: writable iterators?

2011-06-22 Thread Mel
: ... 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

Re: writable iterators?

2011-06-22 Thread Neal Becker
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

Re: writable iterators?

2011-06-22 Thread Chris Kaynor
You could probably implement something like this using generators and the send method (note the example is untested and intended for 2.6: I lack Python on this machine): def gen(list_): for i, v in enumerate(list_): list_[i] = yield v def execute(): data = range(10) iterator =

Re: writable iterators?

2011-06-22 Thread Thomas 'PointedEars' Lahn
Mel wrote: Steven D'Aprano wrote: 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

Re: writable iterators?

2011-06-22 Thread MRAB
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 #

Re: writable iterators?

2011-06-22 Thread Steven D'Aprano
On Thu, 23 Jun 2011 09:10 am 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

Re: writable iterators?

2011-06-22 Thread Steven D'Aprano
On Thu, 23 Jun 2011 09:30 am Thomas 'PointedEars' Lahn wrote: Mel wrote: Steven D'Aprano wrote: 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

Re: writable iterators?

2011-06-22 Thread Carl Banks
On Wednesday, June 22, 2011 4:10:39 PM UTC-7, Neal Becker wrote: AFAIK, the above is the only python idiom that allows iteration over a sequence such that you can write to the sequence. And THAT is the problem. In many cases, indexing is much less efficient than iteration. Well, if your

Re: writable iterators?

2011-06-22 Thread FunAt Work
Don't relate it anyhow to foreach of perl I would say, although the behaviour may be same in some aspect -- http://mail.python.org/mailman/listinfo/python-list