Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
module trace and counts
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Steven D'Aprano  
View profile  
 More options Nov 17 2012, 12:47 pm
Newsgroups: comp.lang.python
From: Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>
Date: 17 Nov 2012 17:47:58 GMT
Local: Sat, Nov 17 2012 12:47 pm
Subject: Re: module trace and counts

On Sat, 17 Nov 2012 09:25:02 -0800, rh wrote:
> Is it for or range that is executed 8000 times when I for i in
> range(3,8000,2):

I'm sorry, I don't understand that question.

Is it for what? What "it" are you talking about?

If you run the code:

for i in range(3, 8000, 2):
    pass

the `for` statement executes once, giving 3999 iterations in total.
`range` gets executed once. Nothing is executed 8000 times.

> Maybe the for and the range contributes to that total.

What total?

I'm sure the context of your question is obvious to you, but we're not
mind-readers and have no idea what you have done and what total you have
got. Please explain your question.

--
Steven


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dave Angel  
View profile  
 More options Nov 17 2012, 1:38 pm
Newsgroups: comp.lang.python
From: Dave Angel <d...@davea.name>
Date: Sat, 17 Nov 2012 13:37:23 -0500
Local: Sat, Nov 17 2012 1:37 pm
Subject: Re: module trace and counts
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
over.
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.

--

DaveA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steven D'Aprano  
View profile  
 More options Nov 17 2012, 8:30 pm
Newsgroups: comp.lang.python
From: Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>
Date: 18 Nov 2012 01:30:41 GMT
Local: Sat, Nov 17 2012 8:30 pm
Subject: Re: module trace and counts

On Sat, 17 Nov 2012 13:37:23 -0500, Dave Angel wrote:
> 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.

Off by one.

py> len(range(3, 8000, 2))
3999

--
Steven


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dave Angel  
View profile  
 More options Nov 17 2012, 9:55 pm
Newsgroups: comp.lang.python
From: Dave Angel <d...@davea.name>
Date: Sat, 17 Nov 2012 21:54:31 -0500
Local: Sat, Nov 17 2012 9:54 pm
Subject: Re: module trace and counts
On 11/17/2012 08:30 PM, Steven D'Aprano wrote:
> On Sat, 17 Nov 2012 13:37:23 -0500, Dave Angel wrote:

>> 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.
> Off by one.

> py> len(range(3, 8000, 2))
> 3999

I should have actually let Python figure it.  Instead I knocked off one
because the interval is half-open, and another because it starts at 3.
Then I checked it by subtracting the first from the last and dividing by
2  ( (7999-3)/2 ), but then made the stupid mistake of not adding one
because my interval WAS closed.

--

DaveA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »