def applejuice(q):
print THE FUNCTION NAME!
It should result in "applejuice" as a string.
This also works:
import sys
def applejuice(q):
func_name = sys._getframe().f_code.co_name
print func_name
def applejuice(**args):
print "Running the function 'applejuice'"
pass
or use:
myfunc.__name__
>>> print applejuice.__name__
'applejuice'
Also, see how-to-get-the-function-name-as-string-in-python
import traceback
def applejuice(q):
stack = traceback.extract_stack()
(filename, line, procname, text) = stack[-1]
print procname
I assume this is used for debugging, so you might want to look into the other procedures offered by the traceback
module. They'll let you print the entire call stack, exception traces, etc.
Another way
import inspect
def applejuice(q):
print inspect.getframeinfo(inspect.currentframe())[2]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With