[Python-3000] xrange vs. int.__getslice__

Vladimir 'Yu' Stepanov vys at renet.ru
Tue Jul 4 11:37:12 CEST 2006


Ivan Krstic wrote:
> Vladimir 'Yu' Stepanov wrote:
>   
>> ---------------------------------------------
>>         for i in xrange(100): pass
>> vs.
>>         for i in int[:100]: pass
>> ---------------------------------------------
>>     
>
> I'm a strong -1 on this; it makes it look like float[:100] should also
> be legal and reasonable, but I can't see how it could possibly be.

In general that I thought to stop only on type int :). But your idea to
distribute it on other types seems to me quite good even if it has been
resulted as counter-argument.

It is how much possible to understand slice in Python language is a
reception of a range of values with the certain step. By default this
step is equal to 1 for objects of any type. It is possible to assume,
that the similar behaviour can be at types float, decimal, long and
other. As the method __getslice__ till now is not involved by any
image for numbers.

Advantage of such approach is that it is not necessary to hold
function in space __builtins__. Each numerical object (excepting
unless complex) can describe the number of values.

It is possible to give an example still. We shall tell, it is
necessary to pass on ranges of values with 0 on 1000 numbers with
a floating point.

Example:
-----------------------------
for i in xrange(1000):
i = float(i)
.. do something ..

vs.

for i in float[:1000]:
.. do something ..
-----------------------------

Now for fractional types widely to use this opportunity it will
not turn out. C-API as arguments are transferred only С-`long'
integers. To achieve, that a step of less unit it was now
impossible, therefore as all arguments will be approximated.



More information about the Python-3000 mailing list