Possible Duplicate:
How do I get the name of a function or method from within a Python function or method?
The below code function return it’s name.
It works but I still have to specify the ‘test.’ in front of of the __name__.
Is there any general way to refer the __name__ ?
def test():
print test.__name__
There is no way to access the function name in a python function without using a backtrace.
So, what you want to use is
inspect.stack()[0][3]or, if you want to move it into a separate function,inspect.stack()[1][3](from How do I get the name of a function or method from within a Python function or method?)