class MyClass:
def my_method(self):
print(get_context())
MyClass().my_method()
I need get next line:
MyClass::my_method
sys._getframe(2).f_code.co_name gives me only "my_method". How to get also class name?
class MyClass:
def my_method(self):
print(get_context())
MyClass().my_method()
I need get next line:
MyClass::my_method
sys._getframe(2).f_code.co_name gives me only "my_method". How to get also class name?
You can get your classname by calling __class__.__name__
from self
.
class Foo(object):
def bar(self):
print(self.__class__.__name__)
Foo().bar()
Output: Foo