On Fri, Jul 12, 2002 at 09:36:22AM -0400, Guido van Rossum wrote:
I don't understand what you mean by fragile. I'm not suggesting anything that actually depends on this behavior so I don't see what could break.
If nothing depends on it, what's the point?
To satisfy my perverted obsession for semantic hygiene, of course!
That version of the xrange object was broken.
That's exactly my point. There will be more broken code like this as long as people keep confusing iterators and iterables. Making the language semantically cleaner should help prevent things like this in the long run.
I remember it was pretty hard to actually convince anyone that xrange was broken. When I pointed out that the xrange 'iterator' modified the state of the xrange 'container' people responded that it's ok because this happens with file objects, too...
I don't see what's wrong with the file object. Iterating over a file changes the file's state, that's just a fact of life.
A file object is an iterator pretending to be a container. For historical reasons it uses 'readline' instead of 'next' and an empty string instead of StopIteration but it basically does the same job. A file object is not really a container that can produce iterators of itself.