PEP 276 Simple Iterator for ints

James_Althoff at i2.com James_Althoff at i2.com
Thu Nov 15 21:58:39 CET 2001


David Eppstein wrote:
>Jeff Shannon <jeff at ccvcorp.com> wrote:
>
>> Which is exactly why I think that the Haskell-ish syntax is a bad idea.
This
>> syntax cries out to be a closed interval, and it would be very confusing
if
>> used as a half-open interval.  But that would make it the *only* case of
>> Python using a closed interval.  I find that inconsistency to be *far*
more
>> jarring than the use of range().
>
>I don't buy this argument.  Currently AFAIK the *only* cases of Python
>using intervals at all are range() and xrange(), which I've argued are

Slicing (when using positive indices) is "half-open interval"-like, also.

>unsatisfactory -- what's the point of changing to something better if you
>require it to be consistent with the bad solution currently in place?
>Don't tell me it's for consistency with C, either -- in C, closed and open

>intervals are equally easy.
>
>Let me see if I can list some likely uses of ranges:
>
>- Loops over the elements of a sequence. Better handled by "for item in
>sequence" or, as someone recently suggested, "for index in
>indices(sequence)".

With the expansion of Python into new realms -- I'm thinking specifically
of Jython here -- I think one must broaden one's view a bit.  Jython, for
example, makes it seamless to use Java classes and APIs while programming
in Python.  It is not uncommon in Jython programming to encounter objects
that don't follow the conventions of Python's builtins.  Neither "for item
in sequence:" nor "for index in indices(sequence):", for example, will work
with DefaultTableModel.  And yet DefaultTableModel follows the convention
of indexing -- both for row and column indicies -- using a half-open
interval starting at 0.

Jim






More information about the Python-list mailing list