Created
February 11, 2013 16:52
-
-
Save gamingrobot/4755675 to your computer and use it in GitHub Desktop.
Get calling class
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
def _getName(self): | |
retmod = "Module" | |
frame, module, line, function, context, index = inspect.stack()[2] | |
try: | |
self_argument = frame.f_code.co_varnames[0] # this should be self | |
instance = frame.f_locals[self_argument] | |
retmod = instance.__class__.__name__ | |
except IndexError: | |
retmod = inspect.getmodulename(module) | |
return retmod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment