[Python-Dev] range objects in 3.x

Guido van Rossum guido at python.org
Tue Sep 27 23:16:49 CEST 2011


On Tue, Sep 27, 2011 at 1:21 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> Guido van Rossum wrote:
>>
>> But why offer an API that is an attractive nuisance? I don't think
>> that it is a burden to the user to have to specify "from 0 to 2 inches
>> in 8 steps" instead of "from 0 to 2 inches in 1/4 inch steps". (And
>> what if they tried to say "from 0 to 3 1/4 inches in 1/2 inch steps"
>> ?)
>
> And how many steps in "from 37 3/4 inches to 90 1/4 inches" ?  I don't want
> to have to calculate that.  That's what computers are for.

That's just silly. The number of steps is (stop - start) / step.

> Your last example is no different than today's range(2, 10, 3) -- we don't
> get 10 or 9.

The difference is that most operations on integers, by their nature,
give give exact results, except for division (which is defined as
producing a float in Python 3). Whether float operations give exact
results or not is a lot harder to know, and the various IEEE states
are hard to access.

Just because the US measurement system happens to use only values that
are exactly representable as floats doesn't mean floats are great to
represent measurements. (What if you have to cut a length of string in
three equal pieces?)

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list