Last active
January 1, 2016 03:39
-
-
Save muzhig/8086673 to your computer and use it in GitHub Desktop.
python class name inside it's declaration
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 get_classname(): | |
return traceback.extract_stack()[-2][2] # in inner call | |
def get_classname_for_method_decorator(): | |
return traceback.extract_stack()[-3][2] # in inner call | |
def decorator(func): | |
classname = get_classname_for_method_decorator() | |
return func | |
class Foo(object): | |
class_name = traceback.extract_stack()[-1][2] # in class definition | |
class_name = get_classname() | |
@decorator | |
def foo_method(self): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment