Created
December 29, 2019 05:49
-
-
Save zhangzhhz/36c92e0c5296f519d6e025a989416042 to your computer and use it in GitHub Desktop.
Get the name of the function that is running
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def whoami(): | |
''' | |
To be used within a function. | |
Returns the name of the function whoami() is called in. | |
''' | |
import sys | |
return sys._getframe(1).f_code.co_name | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above will print: