[Python-3000] PEP: rename it.next() to it.__next__(), add a next() built-in

Guido van Rossum guido at python.org
Mon Mar 5 23:07:47 CET 2007


On 3/5/07, python at rcn.com <python at rcn.com> wrote:
> My thought here is that iterators should always be a separate object -- there is no good reason for dir(iter(myfile)) to expose methods that have nothing to do with iteration.  In the case of files, it would not be hard to have a singleton file-iterator object.

The question isn't how hard it would be, but whether it would be the
right thing to do. For iterators where (by nature of the object being
iterated over) there's only one iterator possible, I think returning
self is the right thing to do, as it makes it abundantly clear that
multiple parallel iterations are unsupported. (And let's not get into
the discussion of how to support multiple iterators over files -- we
went over that when we first decided to make files iterable.)

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list