traceback

Determine function name from within that function (without using traceback)

情到浓时终转凉″ 提交于 2019-11-26 01:55:29
问题 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 foo.bar() , is there a way for bar to know bar\'s name? Or better yet, foo.bar \'s name? #foo.py def bar(): print \"my name is\", __myname__ # <== how do I calculate this at runtime? 回答1: Python doesn't have a feature to access the function or its name within the function itself. It has been proposed but rejected.