On 2006-09-27, Tim Chase <[EMAIL PROTECTED]> wrote: >>> To begin with this already fails: >>> >>>>>> for i in xrange(Top): >>> ... print i >> >> What do you expect this to do? Loop forever? > > Perhaps the infinite loop should take half as long as > > >>> for i in xrange(Bottom, Top): print i > > Though then the values when the loop first starts are kinda > ambiguous... :) > > Given the limits of xrange: > > >>> for i in > xrange(10000000000000000000000000,10000000000000000000000009): > ... print i > > Traceback (most recent call last): > File "<stdin>", line 1, in ? > OverflowError: long int too large to convert to int > > I suspect one would have an overflow condition to help break you > out of the loop...
Sometime people want an infinite loop. Personnaly I don't see why I should get an overflow error while doing this: import sys for i in xrange(sys.maxint - 4, sys.maxint + 5): pass I remember in the days when longs and ints were being unified, that some people complained, because without this unification, a loop in which an int counter was incremented would necessarily end when the counter overflowed and this was a good indication there was a bug somewhere. The response to that was, that you could never foresee how your algorithm would be used and that maybe someday someone found a good way to use your algoritm where the counter would go beyond sys.maxint. Following this logic there is no reason why xrange should be limited to ints. > >>> try: > ... for i in range(Top): > ... print i > ... except OverflowError: > ... print 'done!' > > ...and then you time your instruction cycles and your disk reads > so they fall under the read-head at just the right time... [*] > > [*] http://www.catb.org/jargon/html/story-of-mel.html There is no reason to compare what I propose to the story of melvin. All behaviour of the objects would be well defined and could be easily understood to those who would read the documentation. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list