Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

In Python, without using the traceback module, is there a way to determine a function's name from within that function?

Say I have a module foo with a function bar. When executing, is there a way for the bar to know the bar's name? Or better yet,'s name?

def bar():

   print "my name is", __myname__ # <== how do I calculate this at runtime?

1 Answer

0 votes
by (106k points)

To determine the function name without using traceback within that function you can use the inspect.stack method below is the code for the same:-

import inspect

def foo():


Related questions

Browse Categories