[python-win32] range function problem

Jorgensen, Jens jens.jorgensen@tallan.com
Wed, 10 Oct 2001 09:08:06 -0500


No bug. range() builds a list of the numbers in the sequence. You can do
the math. If each item in the list only takes 8 bytes of memory you get
76MB. Each list item probably takes a bit more. You might want to use
xrange instead which doesn't create the list but rather returns an
object that creates each int as it is asked for.

zy wrote:

> I am a new user of python language.
>
> I tested a small program which likes the following:
>
> ********************************************
> * n = 19999999
> * for x in range(2, n/2+1):
> * if n % x == 0:
> * print n, 'equals', x, '*', n/x
> * break
> * else:
> * print n, 'is a prime number'
>
> **********************************************
>
> I found something interesting when the variable 'n' equals 19999999
>
> that my computer seemed crazy because it began to eat my memory
>
> at a surprising speed , the memory amount used just rose from 131M to
> 258M
>
> and the process had no response.
>
> But when the variable 'n' equals 1999999, the program works well.
>
> So I just ran the expression 'range(2, n/2+1)'(n=19999999),and i found
>
> the same situation like the front happened.
>
> So I want to know if it is a bug of the range function.
>
> Thanks first.
>


-- 
Jens B. Jorgensen
jens.jorgensen@tallan.com