There are two ways to do this. You can either do:
def whoami():
"""Returns name of the method."""
import sys
return sys._getframe(1).f_code.co_name
def callersname():
"""Returns name of the caller."""
import sys
return sys._getframe(2).f_code.co_name
Or you can simply do:
import inspect
inspect.stack()[0][3]
This will give you method name. Pretty simple?