[Python-Dev] Single- vs. Multi-pass iterability
Aahz
aahz@pythoncraft.com
Fri, 19 Jul 2002 11:20:29 -0400
On Fri, Jul 19, 2002, Fredrik Lundh wrote:
> aahz wrote:
>>Ping:
>>>
>>> I believe this is where the biggest debate lies: whether "for" should be
>>> non-destructive. I realize we are currently on the other side of the
>>> fence, but i foresee enough potential pain that i would like you to
>>> consider the value of keeping "for" loops non-destructive.
>>
>> Consider
>>
>> for line in f.readlines():
>>
>> in any version of Python.
>
> and? for-in doesn't modify the object returned
> by f.readlines(), and never has.
While technically true, that seems to be sidestepping the point from my
POV. I think that few people see for loops as inherently
non-destructive due to the use case I presented above. Beyond that, the
for loop is itself inherently mutating in Python older than 2.2, which I
see as functionally equivalent to "destructive"; the primary intention
of iterators (from my recollections of the tenor of the discussions) was
to package that mutating state in a way that could capture the
iterability of objects other than sequences.
--
Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/
Project Vote Smart: http://www.vote-smart.org/