is there a way to track the number of times a function is called?

前端 未结 11 1110
情话喂你
情话喂你 2020-11-28 08:56

So i\'m trying to make a function that keeps track how many times a method is called. for example:

a = [1,2,3,4]
a.pop()

i want to know how

11条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 09:01

    Just define a global variable and increment it inside function.

    a = 0
    def some_function():
        global a
        a+=1
        <..Your code.>
    

    This will automatically be incremented as function is used and you can access it globally.

提交回复
热议问题