Skip to content

Instantly share code, notes, and snippets.

@reutsharabani
Created December 27, 2016 15:40
Show Gist options
  • Save reutsharabani/41dc0839f8262f6f2d7d4b9ae6a7cbd7 to your computer and use it in GitHub Desktop.
Save reutsharabani/41dc0839f8262f6f2d7d4b9ae6a7cbd7 to your computer and use it in GitHub Desktop.
Get calling module's name in python
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