I need to know how many times my function has been accessed in my program. Any suggestions other than global variable?
bumsfeld
413
Nearly a Posting Virtuoso
Recommended Answers
Jump to PostHi bumsfeld,
Well, let's think about this. Suppose that we want to create a variable 'count' that records the number of times a function 'myfunc()' is called. If the variable's scope is limited to the function itself, it will disappear off the runtime stack when the function call is …
Jump to PostG-Do,
nice thinking here!I looked in my code samples and found another way, a little strange at first blush, but it works! I commented it heavily for Bumsfeld so he can follow it. You can put a test print in front of count.append(7) to make it more visible.
…
Jump to PostThat is bizarre behavior, vegaseat! What is going on there - are lists remembered in a way that other variables are not? Because I can do the following:
>>> def myfunc(s='s'): ... s += s ... return len(s) ... >>> for k in range(10): ... tally = …
All 11 Replies
G-Do
19
Junior Poster
bumsfeld
commented:
Very interesting code used!
+1
bumsfeld
413
Nearly a Posting Virtuoso
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
G-Do
19
Junior Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
G-Do
19
Junior Poster
bumsfeld
413
Nearly a Posting Virtuoso
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
mawe
6
Junior Poster
G-Do
19
Junior Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.