for loop: range() result has too many items
Dave Angel
davea at ieee.org
Tue Oct 13 18:49:08 EDT 2009
Andre Engels wrote:
> On Tue, Oct 13, 2009 at 11:55 PM, Andre Engels <andreengels at gmail.com> wrote:
>
>
>> for i in range(sys.maxint):
>> if i % 100 =0:
>> print i
>>
>
> Grmbl.... cut-and-paste error... I meant of course:
>
> for i in xrange(sys.maxint):
> if i % 100 =0:
> print i
>
>
What version of Python gives an error on that code? My 2.6.2 works fine.
If you do need a larger xrange, you can easily write your own. Here's
one called brange(). It'd be a bit more work to make the 3-argument
version.
def brange(limit):
i = 0
while i < limit:
yield i
i += 1
More information about the Python-list
mailing list