def applejuice(q):
print THE FUNCTION NAME!
It should result in "applejuice" as a string.
def applejuice(q):
print THE FUNCTION NAME!
It should result in "applejuice" as a string.
You need to explain what your problem is. Because the answer to your question is:
print "applejuice"
def applejuice(**args):
print "Running the fucntion 'applejuice'"
pass
or use:
myfunc.__name__
>>> print applejuice.__name__
'applejuice'
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]
This also works:
import sys
def applejuice(q):
func_name = sys._getframe().f_code.co_name
print func_name
What should it print in this case :
def applejuice():
print "thefunctionname"
orangejuice = applejuice
del applejuice
orangejuice()
?-)