Issue
I want to create some kind of debugging output for python and want to pass the functionname to another function for output.
The only reasonable way I found to do so was:
def foobar():
print 'hello world'
print foobar.__name__
is there something that does the same thing for the current function to improve copy and pasting of that line?
like the C equivalent printf("%s", __func__)
.
Solution
sys._getframe can do that:
import sys
def foobar():
print sys._getframe().f_code.co_name
Answered By - David Robinson
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.