Is there better way to get function name inside the class.
I would like to get and <str> "A.boo"
without using self.boo
statement.
this is the test.py
which I ran
import sys
import traceback
def foo():
print(foo.__name__)
print(foo.__qualname__)
print(sys._getframe().f_code.co_name)
print(traceback.extract_stack()[-2])
foo()
class A:
def boo(self):
print(self.boo.__name__)
print(self.boo.__qualname__)
print(sys._getframe().f_code.co_name)
print(traceback.extract_stack()[-2])
A().boo()
output:
$ python test.py
foo
foo
foo
<FrameSummary file test.py, line 12 in <module>>
boo
A.boo
boo
<FrameSummary file test.py, line 21 in <module>>