python - How to get class name from bound method using inspect? -
this question has answer here:
class myclass: def my_method(self): print(get_context()) myclass().my_method() i need next line:
myclass::my_method sys._getframe(2).f_code.co_name gives me "my_method". how class name?
you can classname calling __class__.__name__ self.
class foo(object): def bar(self): print(self.__class__.__name__) foo().bar() output: foo
Comments
Post a Comment