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 PostLooks like a little lecture on argument passing in Python functions is in order, here are some examples I came up with to illustrate the basics:
# do function arguments stay local? def times3(x): """argument x becomes local to function""" x = x * 3 return x …
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.