Top and Bottom Values [PEP: 326]

Georg Brandl g.brandl-nospam at
Thu Sep 28 10:29:31 CEST 2006

Antoon Pardon wrote:
> On 2006-09-27, OKB (not okblacke) <brenNOSPAMbarn at> wrote:
>> Antoon Pardon wrote:
>>> To begin with this already fails:
>>>>>> for i in xrange(Top):
>>> ...   print i
>>     	What do you expect this to do?  Loop forever?
> Yes that is what I would expect.

For unterminating loops, use while 1:, and if you need the counter,

> If someone would ask me
> to implement a function like xrange it would look something
> like the following (*)
>   def xrange(start=1, stop, step=1):
>     while start < stop:
>       yield start
>       start += step
> Since Top is supposed to be bigger than any other value this would
> indeed loop forever. The only reason that this doesn't work with
> the builtin, is because the builtin xrange insist on its arguments
> being ints instead of allowing duck typing.

xrange() *could* be implemented as shown above, but do you realize
that it would be a severe performance hit compared to the current
implementation, which doesn't give almost all users a benefit at all?


More information about the Python-list mailing list