PEP 234: Iterators

Andrew Dalke dalke at acm.org
Thu May 3 01:42:56 EDT 2001


Stephen Hansen wrote:
>    Okay: I really like the iterators PEP, but to me, I *really* don't like
>any of the names which were chosen for it.
 ...
>    I'd like to read 'iter(object)' as 'iterate(object)' and 'iter(func,
>sequence)' as 'iterator(func, sequence)' since the latter is making an
>iterator on the fly, and not iterating over it...

I've also got to admit to some concern.  It's took me a while to
figure out what iter(callable, sentinel) does - I had to read
the example use before it became clear.  Now I know, but it
doesn't feel right.  If there is a spam(x) and spam(y, z) then
I believe the expectations on the interface for x and y should
be similar, which is not the case here.  (x has to implement
__iter__ or __getitem__ while y is callable).

Is there another case in Python where a single function has
such different expectations on its input depending on the
number of parameters?  The closest I could come up with is
string.split, which isn't all that close.


I can't think of a better name.  Stephen suggests "iterate"
and "iterator" but I feel those names are too close in spelling.
I've noticed that I end up only reading the first few characters
and leaving the rest up to the shape of the word.  These two
words have similar shapes.

The best I could think of was "iterate_until" for the sentinel
version.  That would make it the 2nd builtin to use an '_' (the
only other one I know of is 'raw_input'.

Any chance there can be some user tests like there were for
list comprehensions?

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list