I have a case, let's say:
class A:
def store():
name = 'unknown'
for name in inspect.stack():
if 'method_a' in name:
print('Called x times from method A')
if 'method_b' in name:
print('Called x times from method B')
class B:
def __init__():
self.a = A()
def method_a():
self.a.store()
self.a.store()
def method_b():
self.a.store()
self.a.store()
self.a.store()
So, I'm interested to know how many times has the store
method been called from methodA
and from methodB
from class B
. I can't modify class B
, the logic should be implemented only from store
method of class A
.
Does the inspect
library offer such a feature? Or, I can extract the result I want in some other way?