
I think this thread is ready to die.
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 don't think that the language can help this. There's nothing oyu can do to remove the wart from file objects.
I remember it was pretty hard to actually convince anyone that xrange was broken.
Huh? IIRC I said it was broken right away and pushed Raymond to fix it.
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...
A confusion that you don't stamp out by "fixing" files.
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.
In what sense does it pretend to be a container? File objects are what they are; they have rich semantics for a reason.
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.
I think this thread is ready to die. --Guido van Rossum (home page: http://www.python.org/~guido/)