I need to count the number of times recursion in a python program. So basically I need a static variable kind of thing (like in C) which can count the number of times the function is called.
Just pass a counter with the recursion
def recur(n, count=0):
if n == 0:
return "Finished count %s" % count
return recur(n-1, count+1)
Or im sure there is some fancy decorator, Im gonna investigate that now...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With