Skip to content

Instantly share code, notes, and snippets.

@zhangzhhz
Created December 29, 2019 05:49
Show Gist options
  • Save zhangzhhz/36c92e0c5296f519d6e025a989416042 to your computer and use it in GitHub Desktop.
Save zhangzhhz/36c92e0c5296f519d6e025a989416042 to your computer and use it in GitHub Desktop.
Get the name of the function that is running
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
@zhangzhhz
Copy link
Author

def test():
    print(f'{whoami()}() says hello..')

test()

The above will print:

test() says hello..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment