module trace and counts

Dave Angel d at
Sat Nov 17 19:37:23 CET 2012

On 11/17/2012 12:25 PM, rh wrote:
> Is it for or range that is executed 8000 times when I
> for i in range(3,8000,2):
Nothing is executed 8000 times.  I figure it at 3998 times.  Anyway,
neither the for nor the range is executed multiple times.  Deciphering
this depends on whether this is Python 2.x or Python 3.x.

If Python 2.x, range returns a list of 3998 items, and that is iterated
If Python 3.x, range returns a range object, which has an __iter__()
special method.  That method gets called 3999 times, and the last time
it throws an exception to end the loop.

> Maybe the for and the range contributes to that total.
> Can anyone recommend their favorite trace or profile type tool that
> spits out an html page? I like trace because I don't have to insert my
> program into it but would like a html page too.



More information about the Python-list mailing list