Created
December 27, 2016 15:40
-
-
Save reutsharabani/41dc0839f8262f6f2d7d4b9ae6a7cbd7 to your computer and use it in GitHub Desktop.
Get calling module's name in python
This file contains 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
import inspect | |
def whoami(): | |
'''Return the module name of where the call came from.''' | |
frame_records = inspect.stack()[1] | |
calling_module = inspect.getmodulename(frame_records[1]) | |
return calling_module | |
# Test | |
if __name__ == "__main__": | |
print whoami() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment