B
beliavsky
Is there a way in Python to print the name of the function one is
currently in?
The code
def foo():
debug = True
if (debug):
print "entered",__name__
x = foo()
outputs "entered __main__"
I want to print "entered foo". Of course I could just hard-code the
string "foo" in a print statement, but I don't want to have the
function name written in more than one place.
currently in?
The code
def foo():
debug = True
if (debug):
print "entered",__name__
x = foo()
outputs "entered __main__"
I want to print "entered foo". Of course I could just hard-code the
string "foo" in a print statement, but I don't want to have the
function name written in more than one place.