[Python-Dev] Single- vs. Multi-pass iterability

Fredrik Lundh fredrik@pythonware.com
Fri, 19 Jul 2002 18:07:21 +0200


aahz wrote:

> While technically true, that seems to be sidestepping the point from =
my
> POV.

really?  are you arguing that when Ping says that for-in shouldn't
destroy the target, he's really saying that python shouldn't allow
methods to have side effects if they can be called from an
expression used in a for-in statement?  why would he say that?

> I think that few people see for loops as inherently non-destructive
> due to the use case I presented above.

I think most people can tell the difference between an object and
a method with side-effects.  I doubt they would be able to get much
done in Python if they couldn't.

> Beyond that, the for loop is itself inherently mutating in Python
> older than 2.2

in what sense?  it calls the object's __getitem__ method with an
integer index value, until it gets an IndexError.  in what way is that
"inherently mutating"?

</F>